Kamis, 09 April 2015

KONVERSI SUHU

Saya Akan Sharing Bagaiman Codingan Konversi Suhu Pada Netnbeans Visual :)

public class KonversiSuhu extends javax.swing.JFrame {
    public KonversiSuhu() {
        initComponents();


        this.setLocationRelativeTo(this.getRootPane());
    }

    public void celfa() {

        double celcius, hasil;
        try {
            if (Txt1.getText().length() == 0) {
                JOptionPane.showMessageDialog(rootPane, "Input Kosong");
                Txt1.requestFocus();
            } else {
                celcius = Double.parseDouble(Txt1.getText());
                hasil = (celcius * 1.8) + 32;
                DecimalFormat format = new DecimalFormat("#.####");
                Lbljwb1.setText(String.valueOf(format.format(hasil) + " °F "));
            }

        } catch (Exception e) {

        }
    }

    public void celke() {
        double celcius, hasil;
        try {
            if (Txt1.getText().length() == 0) {
                JOptionPane.showMessageDialog(rootPane, "Input Kosong");
                Txt1.requestFocus();
            } else {
                celcius = Double.parseDouble(Txt1.getText());
                hasil = celcius + 273;
                DecimalFormat format = new DecimalFormat("#.####");
                Lbljwb1.setText(String.valueOf(format.format(hasil) + " °K "));
            }

        } catch (Exception e) {

        }
    }

    public void celre() {

        double celcius, hasil;
        try {
            if (Txt1.getText().length() == 0) {
                JOptionPane.showMessageDialog(rootPane, "Input Kosong");
                Txt1.requestFocus();
            } else {
                celcius = Double.parseDouble(Txt1.getText());
                hasil = celcius * 0.8;
                DecimalFormat format = new DecimalFormat("#.####");
                Lbljwb1.setText(String.valueOf(format.format(hasil) + " °R "));
            }

        } catch (Exception e) {

        }
    }

    public void facel() {

        double fahrenheit, hasil;
        try {
            if (Txt2.getText().length() == 0) {
                JOptionPane.showMessageDialog(rootPane, "Input Kosong");
                Txt2.requestFocus();
            } else {
                fahrenheit = Double.parseDouble(Txt2.getText());
                hasil = (0.6 * fahrenheit) - 32;
               DecimalFormat format = new DecimalFormat("#.####");
                Lbljwb2.setText(String.valueOf(format.format(hasil)+ " °C "));
            }

        } catch (Exception e) {

        }
    }

    public void fakel() {
        double fahrenheit, hasil;
        try {
            if (Txt2.getText().length() == 0) {
                JOptionPane.showMessageDialog(rootPane, "Input Kosong");
                Txt2.requestFocus();
            } else {
                fahrenheit = Double.parseDouble(Txt2.getText());
                hasil = (0.6 * fahrenheit) - 32 + 273;
                DecimalFormat format = new DecimalFormat("#.####");
                Lbljwb2.setText(String.valueOf(format.format(hasil)+ " °K "));
            }

        } catch (Exception e) {

        }
    }

    public void fare() {
        double fahrenheit, hasil;
        try {
            if (Txt2.getText().length() == 0) {
                JOptionPane.showMessageDialog(rootPane, "Input Kosong");
                Txt2.requestFocus();
            } else {
                fahrenheit = Double.parseDouble(Txt2.getText());
                hasil = (0.4 * fahrenheit) - 32;
                DecimalFormat format = new DecimalFormat("#.####");
                Lbljwb2.setText(String.valueOf(format.format(hasil)+ " °R "));
            }

        } catch (Exception e) {

        }
    }
private void BtnkeluarActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        int jawab = javax.swing.JOptionPane.showConfirmDialog(null, " Yakin Mau Keluar ? ", " Konfirmasi ", javax.swing.JOptionPane.YES_NO_CANCEL_OPTION);
        if (jawab == 0) {
            this.dispose();
        }
    }                                        

    private void BtnhapusActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        Txt1.setText("");
        Txt2.setText("");
        Lbljwb1.setText(".....");
        Lbljwb2.setText(".....");
        Txt1.requestFocus();
    }                                       

    private void BtnFActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        celfa();

    }                                   

    private void BtnKActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        celke();
    }                                   

    private void BtnRActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        celre();
    }                                   

    private void BtnCActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        facel();
    }                                   

    private void BtnK1ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        fakel();
    }                                    

    private void BtnR1ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        fare();

    }           


Outputnya Akan tampin Seperti Ini :