RSS

Program Konversi Suhu dengan GUI

26 Nov

LISTING PROGRAM:

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

 
3 Comments

Posted by on 26 November 2010 in Program-Program Java

 

3 responses to “Program Konversi Suhu dengan GUI

  1. jaybuton

    18 December 2010 at 1:22 pm

    thank’s ya sbelumnya,,,
    menarik…harus di coba..
    sukses trus ya.

     
  2. damaisubimawanto

    18 December 2010 at 4:05 pm

    iya, sama-sama.. terima kasih sebelumnya ya..🙂

     
  3. FAROS

    14 February 2012 at 6:29 pm

    BISA DI TERANGKAN LEBIH JELAS NGGA GAN,..
    BINGUNG ANE,..

    MULAI DARI PERTAMA

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: