import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
class convert extends JFrame implements ActionListener
{
Container konten = new Container();
JPanel panel0 = new JPanel();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
int fahrenheit;
int celcius;
int reamur;
int kelvin;
JLabel cl = new JLabel();
JTextField clc = new JTextField(5);
JLabel fr = new JLabel();
JTextField frh = new JTextField(5);
JLabel kl = new JLabel();
JTextField klv = new JTextField(5);
JLabel rm = new JLabel();
JTextField rmr = new JTextField(5);
JButton hp = new JButton("KELUAR");
JButton cv = new JButton("KONVERT");
public convert() {
super("Program Konversi Suhu");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(40,100);
this.setSize(400,200);
konten=getContentPane();
konten.setLayout(new FlowLayout(FlowLayout.CENTER));
cl.setText("Masukan Suhu dalam Celcius : ");
fr.setText("Suhu dalam Fahrenheit : ");
kl.setText("Suhu dalah Kelvin : ");
rm.setText("Suhu dalam Reamur : ");
panel0.setLayout(new GridLayout(6,2));
panel0.add(cl);
panel0.add(clc);
panel0.add(fr);
panel0.add(frh);
frh.setEditable(false);
panel0.add(kl);
panel0.add(klv);
klv.setEditable(false);
panel0.add(rm);
panel0.add(rmr);
rmr.setEditable(false);
panel1.add(hp);
panel1.add(cv);
cv.addActionListener(this);
hp.addActionListener(this);
panel2.setLayout(new BorderLayout());
panel2.add(panel1, BorderLayout.SOUTH);
konten.add(panel0);
konten.add(panel2);
show();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==hp)
System.exit(0);
if(e.getSource()==cv)
{
int fahrenheit,celcius,reamur,kelvin;
String fah,rea,kel;
celcius=Integer.parseInt(clc.getText());
fahrenheit = (9/5) * celcius + 32;
kelvin = celcius + 273;
reamur = (4 * celcius)/5;
fah=String.valueOf(fahrenheit);
kel=String.valueOf(kelvin);
rea=String.valueOf(reamur);
frh.setText(" "+fah);
klv.setText(" "+kel);
rmr.setText(" "+rea);
}
}
}
public class convertsuhu{
public static void main(String args []) {
convert zaki=new convert();
zaki.setVisible(true);
}
}
Berikut adalah OUTPUTnya:
Semoga membantu >_<!
Tidak ada komentar:
Posting Komentar