PROGRAM JAVA BERBASIS GUI 2 (Konversi Suhu)
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class konversisuhugui extends JFrame
{
private JButton c, k, f, r;
public konversisuhugui()
{
super("Konversi Suhu");
Container container = getContentPane();
container.setLayout(new FlowLayout());
c = new JButton("Celcius");
c.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int ce = 0;
String celcius = "";
celcius = JOptionPane.showInputDialog("Besar Suhu Celcius");
ce = Integer.parseInt(celcius);
int ke = ce + 273;
int fa = ce * 9 / 5 + 32;
int re = ce * 4 / 5;
JOptionPane.showMessageDialog(null,ce + " " + "C -> Kelvin = " + ke + "\n" + ce + " " +
"C -> Fahrenheit = " + fa + "\n" + ce + " " + "C -> Reamur = " + re);
}
}
);
container.add(c);
k = new JButton ("Kelvin");
k.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int ke = 0;
String kelvin = "";
kelvin = JOptionPane.showInputDialog("Besar Suhu Kelvin");
ke = Integer.parseInt(kelvin);
int ce = ke - 273;
int fa = (ke - 273) * 9 / 5 + 32;
int re = (ke - 273) * 4 / 5;
JOptionPane.showMessageDialog(null,ke + " " + "K -> Celcius = " + ce + "\n" + ke + " " +
"K -> Fahrenheit = " + fa + "\n" + ke + " " + "K -> Reamur = " + re);
}
}
);
container.add(k);
f = new JButton("Fahrenheit");
f.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int fa = 0;
String fahrenheit = "";
fahrenheit = JOptionPane.showInputDialog("Besar Suhu Fahrenheit");
fa = Integer.parseInt(fahrenheit);
int ce = (fa - 32) * 5 / 9;
int ke = (fa - 32) * 5 / 9 + 273;
int re = (fa - 32) * 4 / 9;
JOptionPane.showMessageDialog(null,fa + " " + "F -> Celcius = " + ce + "\n" + fa + " " +
"F -> Kelvin = " + ke + "\n" + fa + " " + "F -> Reamur = " + re);
}
}
);
container.add(f);
r = new JButton("Reamur");
r.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int re = 0;
String reamur = "";
reamur = JOptionPane.showInputDialog("Besar Suhu Reamur");
re = Integer.parseInt(reamur);
int ce = re * 5 / 4;
int ke = re * 5 / 4 + 273;
int fa = re * 9 / 4 + 32;
JOptionPane.showMessageDialog(null,re + " " + "R -> Celcius = " + ce + "\n" + re + " " +
"R -> Kelvin = " + ke +"\n" + re + " " + "R -> Fahrenheit = " + fa);
}
}
);
container.add(r);
setSize(380,70);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[]abi)
{
konversisuhugui test = new konversisuhugui();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.print("Pilih suhu yang ingin di konversikan !");
}
}
Tidak ada komentar:
Posting Komentar