Rabu, 29 Februari 2012

Script Membuat Aplikasi Konversi Suhu Pada Java

ini adalah Script Konversi Suhu yang dibuat pada program membuat aplikasi Java. program ini saya buat saat saya mendapat tugas dari dosen pemrograman yang pada akhirnya di demokan kepada dosen kami. di bawah ini adalah script konversi suhu pada java :








package konversi;

import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;

public class sUHU extends JFrame implements ActionListener {

    JLabel judul = new JLabel ("Konversi Suhu");

    JLabel Input = new JLabel ("input");
    JTextField isi = new JTextField();
    String arraypilih[] = {"Celcius","reamure","Fahrenheit","kelvin"};
    JComboBox boxpilih = new JComboBox(arraypilih);

    JLabel konvert = new JLabel ("ke");
    JRadioButton btncelcius = new JRadioButton ("celcius");
    JRadioButton btnreamure = new JRadioButton ("reamure");
    JRadioButton btnkelvin = new JRadioButton ("kelvin");
    JRadioButton btnfahrenheit = new JRadioButton ("fahrenheit");

    JLabel ket = new JLabel ("hasil");
    JTextField hasil = new JTextField();
    JButton btnkonversi = new JButton ("convert");
   
    JButton btnclear = new JButton ("Reset");

    JPanel convert = new JPanel();

sUHU(){
    setTitle ("Konversi Suhu");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    convert.setLayout(null);

    judul.setBounds(145, 5, 150, 10);

    Input.setBounds(10, 50, 50, 30);
    isi.setBounds(80, 50, 150, 30);
    boxpilih.setBounds(250, 50, 150, 30);

    konvert.setBounds(10, 95, 50, 30);

    btncelcius.setBounds(250, 95, 150, 30);
    btnreamure.setBounds(80, 95, 150, 30);
    btnreamure.addActionListener(this);

    btnkelvin.setBounds(80, 130, 150, 30);
    btnkelvin.addActionListener(this);

    btnfahrenheit.setBounds(80, 165, 150, 30);
    btnfahrenheit.addActionListener(this);

    ket.setBounds(10, 210, 50, 30);
    hasil.setBounds(80, 210, 150, 30);
    btnkonversi.setBounds(250, 210, 150, 30);
    btnkonversi.addActionListener(this);
    btnkonversi.setBackground(Color.white);

    btnclear.setBounds(250, 245, 150, 30);
    btnclear.addActionListener(this);

    convert.add(judul);
    convert.add(Input);
    convert.add(isi);
    convert.add(boxpilih);
    convert.add(konvert);
    convert.add(btncelcius);
    convert.add(btnreamure);
    convert.add(btnkelvin);
    convert.add(btnfahrenheit);
    convert.add(ket);
    convert.add(hasil);
    convert.add(btnkonversi);
    convert.add(btnclear);

    getContentPane().add(convert);
    convert.setBackground(Color.GREEN);
    }


public void actionPerformed(ActionEvent e) {
        float c,r,k,f;       
        if(e.getSource()==btnkonversi){
            if(boxpilih.getSelectedItem().equals("Celcius") && btnreamure.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnkelvin.setEnabled(false);
                btncelcius.setEnabled(false);
                c=  Float.parseFloat(isi.getText());
                r=  (c*4)/5;
                hasil.setText(" "+r);
           
            }else if(boxpilih.getSelectedItem().equals("Celcius") && btnkelvin.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                c= Float.parseFloat(isi.getText());
                k= (c+273);
                hasil.setText(" "+k);
            }else if(boxpilih.getSelectedItem().equals("Celcius") && btnfahrenheit.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                c= Float.parseFloat(isi.getText());
                f= ((c *9)/5) + 32;
                hasil.setText(" "+f);
            }else if(boxpilih.getSelectedItem().equals("Celcius") && btncelcius.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btnfahrenheit.setEnabled(false);
                c= Float.parseFloat(isi.getText());
                hasil.setText(" "+c);
            }else
            if(boxpilih.getSelectedItem().equals("reamure") && btnreamure.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnkelvin.setEnabled(false);
                btncelcius.setEnabled(false);
                r=  Float.parseFloat(isi.getText());
                hasil.setText(" "+r);

            }else if(boxpilih.getSelectedItem().equals("reamure") && btnkelvin.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                r= Float.parseFloat(isi.getText());
                k= (((r*5)/4)+273);
                hasil.setText(" "+k);
            }else if(boxpilih.getSelectedItem().equals("reamure") && btnfahrenheit.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                r= Float.parseFloat(isi.getText());
                f= ((r*9)/4) + 32;
                hasil.setText(" "+f);
            }else if(boxpilih.getSelectedItem().equals("reamure") && btncelcius.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btnfahrenheit.setEnabled(false);
                r= Float.parseFloat(isi.getText());
                c=((r*5)/4);
                hasil.setText(" "+c);
            }else
            if(boxpilih.getSelectedItem().equals("Fahrenheit") && btnreamure.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnkelvin.setEnabled(false);
                btncelcius.setEnabled(false);
                f=  Float.parseFloat(isi.getText());
                r=  (((f-32)*4)/9);
                hasil.setText(" "+r);

            }else if(boxpilih.getSelectedItem().equals("Fahrenheit") && btnkelvin.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                f= Float.parseFloat(isi.getText());
                k= (((f-32)*5)/9)+273;
                hasil.setText(" "+k);
            }else if(boxpilih.getSelectedItem().equals("Fahrenheit") && btnfahrenheit.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                f= Float.parseFloat(isi.getText());
                hasil.setText(" "+f);
            }else if(boxpilih.getSelectedItem().equals("Fahrenheit") && btncelcius.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btnfahrenheit.setEnabled(false);
                f= Float.parseFloat(isi.getText());
                c=(((f-32)*5)/9);
                hasil.setText(" "+c);
            }else
            if(boxpilih.getSelectedItem().equals("kelvin") && btnreamure.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnkelvin.setEnabled(false);
                btncelcius.setEnabled(false);
                k=  Float.parseFloat(isi.getText());
                r=  ((k-273)*4)/5;
                hasil.setText(" "+r);

            }else if(boxpilih.getSelectedItem().equals("kelvin") && btnkelvin.isSelected())
            {
                btnfahrenheit.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                k= Float.parseFloat(isi.getText());
                hasil.setText(" "+k);
            }else if(boxpilih.getSelectedItem().equals("kelvin") && btnfahrenheit.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btncelcius.setEnabled(false);
                k= Float.parseFloat(isi.getText());
                f= (((k-273)*9)/5) + 32;
                hasil.setText(" "+f);
            }else if(boxpilih.getSelectedItem().equals("kelvin") && btncelcius.isSelected())
            {
                btnkelvin.setEnabled(false);
                btnreamure.setEnabled(false);
                btnfahrenheit.setEnabled(false);
                k= Float.parseFloat(isi.getText());
                c= ((k-273)*5)/5;
                hasil.setText(" "+c);
            }
        }else if(e.getSource()==btnclear)
            {
                btnfahrenheit.setEnabled(true);
                btnreamure.setEnabled(true);
                btnkelvin.setEnabled(true);
                btncelcius.setEnabled(true);
                btnfahrenheit.setSelected(false);
                btnreamure.setSelected(false);
                btnkelvin.setSelected(false);
                btncelcius.setSelected(false);
                hasil.setText("");
            }
}
    public static void main(String[] args) {
        // TODO code application logic here
        sUHU tugas = new sUHU();
        tugas.setSize(450, 350);
        tugas.setVisible(true);
    }
}

0 komentar:

Poskan Komentar

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Sweet Tomatoes Printable Coupons