Program java sederhana: konversi fahrenheit ke celcius

Posted: November 4, 2010 in JAVA PROGRAMMING

Assalamualaikum wr.wb_

Graphics Programming

Graphical User Interface (GUI) digunakan untuk mempermudah pemakaian suatu sistem. GUI terdiri dari component-component GUI yang berinteraksi dengan pemakai. Java menyediakan component-component tersebut, untuk membuat GUI.

Berikut ini adalah contoh program java GUI sederhana, yaitu konversi suhu fahrenheit ke celcius

______________________________________________________________

import java.awt.*;

import java.awt.event.*;  ///

import javax.swing.*;

import java.awt.Color;

class tampil extends JFrame implements ActionListener ///

{

Label title = new Label(“Convert Fahrenheit to Celsius”);

Label lbl1 = new Label(“Fahrenheit: “);

TextField txt1      =new TextField (10);

Label lbl2 = new Label(“Celcius   : “);

TextField txt2      =new TextField (10);

Button btn1=new Button(“Konversikan”);

Button btn2=new Button(“Keluar”);

Container c=new Container();

int fahrTemp ;

int celTemp ;

tampil()

{

c=getContentPane();

c.setLayout(new FlowLayout(FlowLayout.LEFT,50,20));

c.add(lbl1);

{c.setBackground(Color.green);}

c.add(txt1);

c.add(btn1);

c.add(lbl2);

c.add(txt2);

c.add(btn2);

btn1.addActionListener(this);

btn2.addActionListener(this);

txt2.setEditable( false );

c.setBackground(Color.pink);;

setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==btn2)

System.exit(0);

if(e.getSource()==btn1)

{

int fahrTemp,celsTemp;

String s;

fahrTemp=Integer.parseInt(txt1.getText());

celTemp = ((fahrTemp-32) * 5) / 9;

s=String.valueOf(celTemp);

txt2.setText(” “+s);

}

}

}

public class lat4 {

public static void main ( String[] args )

{

tampil fahr = new tampil() ;

fahr.setSize( 200, 350 );

fahr.setVisible( true );

}}

__________________________________________________________

berikut ini screenshot dari program:

screenshoot


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