Program matrix GUI dengan netbeans

Pada kali ini saya akan menjelaskan, bagaimana sih cara bikin program matrix sederhana berbasis GUI dengan netbeans ??? Cara nya adalah :

1) Buatlah Output seperti ini 
 
   
2) Lalu buatlah codingan, kalo ga ngerti bikinnya. Cocokin sama codingan yang ini.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * matrix1.java
 *
 * Created on 28 Mar 13, 8:38:18
 */

package matrix1;

/**
 *
 * @author USER
 */
public class matrix1 extends javax.swing.JFrame {

    int ina;
    int inb;
    int inc;
    int ind;

    int ina1;
    int inb1;
    int inc1;
    int ind1;

    int out1;
    int out2;
    int out3;
    int out4;

    int det1;

    int plusClick;
    int minusClick;

    public matrix1() {
        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() {

      
                    

    private void plusActionPerformed(java.awt.event.ActionEvent evt) {                                   
        ina =(Integer.valueOf(String.valueOf(e1.getText())));
        inb =(Integer.valueOf(String.valueOf(e2.getText())));
        inc =(Integer.valueOf(String.valueOf(e3.getText())));
        ind =(Integer.valueOf(String.valueOf(e4.getText())));
        plusClick=1;

    }                                  

    private void minusActionPerformed(java.awt.event.ActionEvent evt) {                                    
        ina =(Integer.valueOf(String.valueOf(e1.getText())));
        inb =(Integer.valueOf(String.valueOf(e2.getText())));
        inc =(Integer.valueOf(String.valueOf(e3.getText())));
        ind =(Integer.valueOf(String.valueOf(e4.getText())));
        minusClick=1;
    }                                   

    private void equalsActionPerformed(java.awt.event.ActionEvent evt) {                                     
        ina1 =(Integer.valueOf(String.valueOf(a1.getText())));
        inb1 =(Integer.valueOf(String.valueOf(a2.getText())));
        inc1 =(Integer.valueOf(String.valueOf(a3.getText())));
        ind1 =(Integer.valueOf(String.valueOf(a4.getText())));
    if(plusClick>0){
       out1 = ina + ina1;
       diout1.setText(String.valueOf(out1));
       out2 = inb + inb1;
       diout2.setText(String.valueOf(out2));
       out3 = inc + inc1;
       diout3.setText(String.valueOf(out3));
       out4 = ind + ind1;
       diout4.setText(String.valueOf(out4));
       plusClick=0;
    }
    if(minusClick>0){
       out1 = ina - ina1;
       diout1.setText(String.valueOf(out1));
       out2 = inb - inb1;
       diout2.setText(String.valueOf(out2));
       out3 = inc - inc1;
       diout3.setText(String.valueOf(out3));
       out4 = ind - ind1;
       diout4.setText(String.valueOf(out4));
       minusClick=0;
    }
    }                                    

    private void clearActionPerformed(java.awt.event.ActionEvent evt) {                                    
        a1.setText("");
        a2.setText("");
        a3.setText("");
        a4.setText("");

        e1.setText("");
        e2.setText("");
        e3.setText("");
        e4.setText("");

        diout1.setText("");
        diout2.setText("");
        diout3.setText("");
        diout4.setText("");

        outdet.setText("");

    }                                   

    private void detActionPerformed(java.awt.event.ActionEvent evt) {                                  
        ina =(Integer.valueOf(String.valueOf(diout1.getText())));
        inb =(Integer.valueOf(String.valueOf(diout2.getText())));
        inc =(Integer.valueOf(String.valueOf(diout3.getText())));
        ind =(Integer.valueOf(String.valueOf(diout4.getText())));
        det1 = (ina*ind) - (inb*inc);
        outdet.setText(String.valueOf(det1));

    }                                 

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

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

    // Variables declaration - do not modify                   
    private javax.swing.JTextField a1;
    private javax.swing.JTextField a2;
    private javax.swing.JTextField a3;
    private javax.swing.JTextField a4;
    private javax.swing.JButton clear;
    private javax.swing.JButton det;
    private javax.swing.JTextField diout1;
    private javax.swing.JTextField diout2;
    private javax.swing.JTextField diout3;
    private javax.swing.JTextField diout4;
    private javax.swing.JTextField e1;
    private javax.swing.JTextField e2;
    private javax.swing.JTextField e3;
    private javax.swing.JTextField e4;
    private javax.swing.JButton equals;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JButton minus;
    private javax.swing.JTextField outdet;
    private javax.swing.JButton plus;
    // End of variables declaration                 

}


3) Coba Running programnya.

Berikut Outputnya




Selesai deh :)

Terima Kasih sudah melihat  Wassalam :)

Posting Komentar