Kamis, 20 Juni 2013

Program Konversi Suhu dengan java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class konversi extends JFrame
{
private JButton c, k, f, r;
public konversi()
{
super("Konversi");
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("Celcius");
ce = Integer.parseInt(celcius);
int ke = ce + 273;
int fa = ce * 9 / 5 + 32;
int re = ce * 4 / 5;
JOptionPane.showMessageDialog(null,"Kelvin = " + ke + "\nFahrenheit = " + fa + "\nReamur = " + 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("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,"Celcius = " + ce + "\nFahrenheit = " + fa + "\nReamur = " + 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("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,"Celcius = " + ce + "\nKelvin = " + ke + "\nReamur = " + 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("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,"Celcius = " + ce + "\nKelvin = " + ke + "\nFahrenheit = " + fa);
}
}
);
container.add(r);
setSize(200,100);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[]abi)
{
konversi test = new konversi();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.print("Silahkan klik pada kotak suhu apa yang anda mau konversikan!\n");
}
}
 
 
 
OUTPUT PROGRAM:


Pilih suhu yang ingin dikonversi
Pilih suhu yang ingin dikonversi
Masukkan nilai suhu tersebut
Hasil penghitungan konversi suhu

Tidak ada komentar:

Posting Komentar