GUI-Program penghitung kalori dan konverter (part 2)

ayoayooo lanjut lagi ngoding programnya yang di part 1..
sekarang aku mau ngasih coding yang buat frame kedua, nama filenya entry.java :


import javax.swing.JOptionPane;
public class entry extends javax.swing.JFrame {
private pria b;
private wanita c;
    /** Creates new form entry */
    public entry() {
        initComponents();
        b=new pria();
        c=new wanita();
    }
    @SuppressWarnings("unchecked")
    //                          
    private void initComponents() {

        l3 = new javax.swing.JLabel();
        l4 = new javax.swing.JLabel();
        tf1 = new javax.swing.JTextField();
        l5 = new javax.swing.JLabel();
        tf2 = new javax.swing.JTextField();
        b2 = new javax.swing.JButton();
        l6 = new javax.swing.JLabel();
        b3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        l3.setFont(new java.awt.Font("Courier New", 0, 18)); // NOI18N
        l3.setText("masukkan data :");

        l4.setText("tinggi badan (cm) :");

        l5.setText("usia (tahun)             :");

        b2.setText("pria");
        b2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b2ActionPerformed(evt);
            }
        });

        l6.setText("jenis kelamin        :");

        b3.setText("wanita");
        b3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(68, 68, 68)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(b2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(b3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(l6, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(l5, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(tf2)
                                .addComponent(tf1, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
                            .addGap(162, 162, 162)))))
            .addGroup(layout.createSequentialGroup()
                .addGap(117, 117, 117)
                .addComponent(l3, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                .addGap(180, 180, 180))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(l3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l5)
                    .addComponent(tf2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(l6)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b2)
                    .addComponent(b3))
                .addContainerGap(181, Short.MAX_VALUE))
        );

        pack();
    }//                        

    private void b2ActionPerformed(java.awt.event.ActionEvent evt) {                                  
        // TODO add your handling code here:
        try{
        b.ta(tf1.getText(), tf2.getText());
        b.setVisible(true);
        }
        catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null,"data salah atau belum terisi lengkap");
        }
    }                                 

    private void b3ActionPerformed(java.awt.event.ActionEvent evt) {                                  
        // TODO add your handling code here:
        try{
        c.ta(tf1.getText(), tf2.getText());
        c.setVisible(true);
    }                                 
        catch(NumberFormatException a){
            JOptionPane.showMessageDialog(null,"data salah atau belum terisi lengkap");
        }
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new entry().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    private javax.swing.JButton b2;
    private javax.swing.JButton b3;
    private javax.swing.JLabel l3;
    private javax.swing.JLabel l4;
    private javax.swing.JLabel l5;
    private javax.swing.JLabel l6;
    private javax.swing.JTextField tf1;
    private javax.swing.JTextField tf2;
    // End of variables declaration                  

}

yang ini coding untuk frame ketiga (frame pria), nama filenya pria.java :

public class pria extends javax.swing.JFrame {
private entry a;
double t, u, bb, kkb;
    /** Creates new form pria */
    public pria() {
        initComponents();
    }

    public void ta(String tinggi, String usia){
        t=Double.parseDouble(tinggi);
        u=Double.parseDouble(usia);
        bb=(t-100)-(0.1*(t-100));
        kkb=66.47+(13.75*bb)+(5*t)-(6.76*u);
        ta1.setText("Kebutuhan Kalori Basal anda adalah:\n"+kkb+" kkal");
    }
    @SuppressWarnings("unchecked")
    //                          
    private void initComponents() {

        rb2 = new javax.swing.JRadioButton();
        rb5 = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        tf4 = new javax.swing.JTextField();
        tf3 = new javax.swing.JTextField();
        tf5 = new javax.swing.JTextField();
        tf6 = new javax.swing.JTextField();
        rb1 = new javax.swing.JRadioButton();
        rb4 = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        ta1 = new javax.swing.JTextArea();
        rb3 = new javax.swing.JRadioButton();
        tf7 = new javax.swing.JTextField();
        l7 = new javax.swing.JLabel();
        b7 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        rb2.setText("joule");

        rb5.setText("kilowatt-hours");

        jButton1.setText("ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        rb1.setText("calori");

        rb4.setText("hp-hours");

        ta1.setColumns(20);
        ta1.setFont(new java.awt.Font("Gisha", 0, 14));
        ta1.setRows(5);
        jScrollPane1.setViewportView(ta1);

        rb3.setText("kilojoule");

        l7.setText("ingin mengkonversi ke satuan energi lain ?");

        b7.setText("back");
        b7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b7ActionPerformed(evt);
            }
        });

        jButton2.setText("clear");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon("D:\\gambar\\background\\clap.gif")); // NOI18N
        jButton3.setText("quit");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rb3)
                            .addComponent(rb4)
                            .addComponent(rb2)
                            .addComponent(rb5)
                            .addComponent(rb1))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tf7)
                            .addComponent(tf4, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tf3)
                            .addComponent(tf6, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                            .addComponent(tf5, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                        .addComponent(jButton3)
                        .addGap(40, 40, 40))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(b7, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(l7, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(112, Short.MAX_VALUE))))
            .addGroup(layout.createSequentialGroup()
                .addGap(105, 105, 105)
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addContainerGap(256, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(b7)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(l7, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tf3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rb1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rb2))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rb3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf6, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rb4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rb5)
                    .addComponent(tf7, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(56, 56, 56))
        );

        pack();
    }//                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        double aa=0,bb=0,cc=0,dd=0,ee=0,hasil;

        if(rb1.isSelected()==true){
            hasil=aa+(kkb*1000);
            tf3.setText(""+hasil);
        }
        if(rb2.isSelected()){
            hasil=bb+(kkb*4186.8);
            tf4.setText(""+hasil);
        }
        if(rb3.isSelected()){
            hasil=cc+(kkb*4.1868);
            tf5.setText(""+hasil);
        }
        if(rb4.isSelected()){
            hasil=dd+(kkb*0.00156);
            tf6.setText(""+hasil);
        }
        if(rb5.isSelected()){
            hasil=ee+(kkb*0.00116);
            tf7.setText(""+hasil);
        }
}                                       

    private void b7ActionPerformed(java.awt.event.ActionEvent evt) {                                  
        // TODO add your handling code here:
        a=new entry();
        a.setVisible(true);
}                                 

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        tf3.setText("");
        tf4.setText("");
        tf5.setText("");
        tf6.setText("");
        tf7.setText("");
}                                       

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here
        System.exit(0);
}                                       

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new pria().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    private javax.swing.JButton b7;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel l7;
    private javax.swing.JRadioButton rb1;
    private javax.swing.JRadioButton rb2;
    private javax.swing.JRadioButton rb3;
    private javax.swing.JRadioButton rb4;
    private javax.swing.JRadioButton rb5;
    private javax.swing.JTextArea ta1;
    private javax.swing.JTextField tf3;
    private javax.swing.JTextField tf4;
    private javax.swing.JTextField tf5;
    private javax.swing.JTextField tf6;
    private javax.swing.JTextField tf7;
    // End of variables declaration                  

}

Penjelasan lagi :
untuk frame pertama, aku sambungkan ke frame kedua, nah jika konsumen meng-klik tombol "pria" yang di frame kedua, maka akan ke frame selanjutnya, di frame ketiga (frame pria), jika meng-klik tombol "wanita", maka akan menuju ke frame keempat (frame wanita)
coding untuk frame wanita (wanita.java) dan frame pria secara keseluruhan sama, tapi ada perbedaan pada rumus penghitungan kalorinya, walaupun tampilan GUI-nya sama.
Nah untuk frame wanita, ganti saja bagian berwarna merah yang ada pada frame pria dengan coding ini :

 t=Double.parseDouble(tinggi);
 u=Double.parseDouble(usia);
bb=(t-100)-(0.1*(t-100));
kkb=65.52+(9.56*bb)+(1.7*t)-(4.77*u);
ta2.setText("Kebutuhan Kalori Basal anda adalah:\n"+kkb+" kkal (kilokalori)");

Komentar