Senin, 28 Oktober 2013 | |

Contoh Program Java 2


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package abriliant;
import java.math.BigDecimal;
import java.math.RoundingMode;


/**
 *
 * @author Axioo
 */
public class TEMPERATURE extends javax.swing.JFrame {
    private double b;
    private int a;
    private String teks;

    /**
     * Creates new form TEMPERATURE
     */
    public TEMPERATURE() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        kelvinbutton = new javax.swing.JRadioButton();
        reamurbutton = new javax.swing.JRadioButton();
        ffarenheitbutton = new javax.swing.JRadioButton();
        Convertbutton = new javax.swing.JButton();
        hasillabel = new javax.swing.JLabel();
        celciusbutton = new javax.swing.JRadioButton();
        Kelvin = new javax.swing.JRadioButton();
        Reamur = new javax.swing.JRadioButton();
        Fahrenheit = new javax.swing.JRadioButton();
        Celcius = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        SUHU = new javax.swing.JTextField();

        jRadioButtonMenuItem1.setSelected(true);
        jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        buttonGroup1.add(kelvinbutton);
        kelvinbutton.setSelected(true);
        kelvinbutton.setText("kelvin");
        kelvinbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kelvinbuttonActionPerformed(evt);
            }
        });

        buttonGroup1.add(reamurbutton);
        reamurbutton.setText("reamur");
        reamurbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reamurbuttonActionPerformed(evt);
            }
        });

        buttonGroup1.add(ffarenheitbutton);
        ffarenheitbutton.setText("fahreinheit");

        Convertbutton.setText("convert");
        Convertbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConvertbuttonActionPerformed(evt);
            }
        });

        buttonGroup1.add(celciusbutton);
        celciusbutton.setText("celcius");

        buttonGroup2.add(Kelvin);
        Kelvin.setText("Kelvin");

        buttonGroup2.add(Reamur);
        Reamur.setText("Reamur");
        Reamur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReamurActionPerformed(evt);
            }
        });

        buttonGroup2.add(Fahrenheit);
        Fahrenheit.setText("Fahrenheit");

        buttonGroup2.add(Celcius);
        Celcius.setSelected(true);
        Celcius.setText("Celcius");

        jLabel1.setText("Disalin Ke :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Convertbutton)
                        .addGap(18, 18, 18)
                        .addComponent(hasillabel, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Kelvin)
                                .addGap(18, 18, 18)
                                .addComponent(Reamur)
                                .addGap(18, 18, 18)
                                .addComponent(Fahrenheit))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(kelvinbutton)
                                        .addGap(18, 18, 18)
                                        .addComponent(reamurbutton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGap(0, 0, Short.MAX_VALUE)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(79, 79, 79)))
                                .addComponent(ffarenheitbutton)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(celciusbutton)
                            .addComponent(Celcius)))
                    .addComponent(SUHU))
                .addContainerGap(245, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(SUHU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Kelvin, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Reamur, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Fahrenheit, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Celcius, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(52, 52, 52)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kelvinbutton)
                    .addComponent(reamurbutton)
                    .addComponent(ffarenheitbutton)
                    .addComponent(celciusbutton))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Convertbutton)
                    .addComponent(hasillabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

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

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

    private void ConvertbuttonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        a=Integer.parseInt(SUHU.getText());
       
        if (Kelvin.isSelected()){
            if (reamurbutton.isSelected()){
            b=(a-273.15)/(5*4);
            teks="kelvin";
            }
            else if (ffarenheitbutton.isSelected()){
            b=(a-273.15)/(5*9)+32;
            teks="fahrenheit";
            }
            else if (celciusbutton.isSelected()){
            b=a-273.15;
            teks="celcius";
            }
        }
        else if (Reamur.isSelected()){
            if (kelvinbutton.isSelected()){
            b=(a/(4*5))+273.15;
            teks="kelvin";
            }
            else if (ffarenheitbutton.isSelected()){
            b=(a/(4*9))+32;
            teks="fahrenheit";
            }
            else if (celciusbutton.isSelected()){
            b=a/(4*5);
            teks="celcius";
            }
        }
        else if (Fahrenheit.isSelected()){
            if (kelvinbutton.isSelected()){
            b=(a-32)/(9*5)+273.15;
            teks="kelvin";
            }
            else if (reamurbutton.isSelected()){
            b=(a-32)/(9*4);
            teks="reamur";
            }
            else if (celciusbutton.isSelected()){
            b=(a-32)/(9*5);
            teks="celcius";
            }
        }
        else {
            if (kelvinbutton.isSelected()){
            b=a+273.15;
            teks="kelvin";
            }
            else if (reamurbutton.isSelected()){
            b=a/(5*4);
            teks="reamur";
            }
            else if (ffarenheitbutton.isSelected()){
            b=(a/(5*9))+32;
            }
        }
       
        BigDecimal komaTerbatas1 = new BigDecimal (b).setScale(2,RoundingMode.UP);
        hasillabel.setText(komaTerbatas1+""+teks);
       
       
       
    }                                            

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TEMPERATURE.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TEMPERATURE.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TEMPERATURE.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TEMPERATURE.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TEMPERATURE().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JRadioButton Celcius;
    private javax.swing.JButton Convertbutton;
    private javax.swing.JRadioButton Fahrenheit;
    private javax.swing.JRadioButton Kelvin;
    private javax.swing.JRadioButton Reamur;
    private javax.swing.JTextField SUHU;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JRadioButton celciusbutton;
    private javax.swing.JRadioButton ffarenheitbutton;
    private javax.swing.JLabel hasillabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
    private javax.swing.JRadioButton kelvinbutton;
    private javax.swing.JRadioButton reamurbutton;
    // End of variables declaration
}

0 komentar:

Posting Komentar