tugas kalkulator, henry n.2012420114

tugas kalkulator, henry n.2012420114

public class calc extends javax.swing.JFrame {
    boolean k, l, m;
  
    /**
     * Creates new form calc
     */
    public calc() {
        initComponents();
         hasil.setHorizontalAlignment(JTextField.RIGHT);
    }
    int plusklik;
    int minklik;
    int kaliklik;
    int bagiklik;
    int decklik;
    int binklik;
    int octklik;
    int hexklik;
    double angka1;
    double angka2;
    double total;
    int decbin;
    int dechex;
    int decoct;
    int bindec;
    int binhex;
    int binoct;
    int hexbin;
    int hexoct;
    int hexdec;
    int octbin;
    int octdec;
    int octhex;
   
    String operasi="des",operasi1="";
   
    public void konvers(){
        try{
            String j=hasil.getText();
            if(operasi.equalsIgnoreCase("bin")&&operasi1.equalsIgnoreCase("des")){
                hasil.setText(""+Integer.parseInt(j,2));
                operasi="des";
           
            }
           
            else if(operasi.equalsIgnoreCase("bin") && operasi1.equalsIgnoreCase("oct")){
                int a=Integer.parseInt(j,2);
                hasil.setText(""+Integer.toOctalString(a));
                operasi="oct";
            }
           
            else if(operasi.equalsIgnoreCase("bin")&& operasi1.equalsIgnoreCase("hex")){
                int a=Integer.parseInt(j,2);
                hasil.setText(""+Integer.toHexString(a));
                operasi="hex";
            }else
            if(operasi.equalsIgnoreCase("oct")&&operasi1.equalsIgnoreCase("des")){
                hasil.setText(""+Integer.parseInt(j,8));
                operasi="des";
           
            }
           
            else if(operasi.equalsIgnoreCase("oct") && operasi1.equalsIgnoreCase("bin")){
                int a=Integer.parseInt(j,8);
                hasil.setText(""+Integer.toOctalString(a));
                operasi="bin";
            }
           
            else if(operasi.equalsIgnoreCase("oct")&& operasi1.equalsIgnoreCase("hex")){
                int a=Integer.parseInt(j,8);
                hasil.setText(""+Integer.toHexString(a));
                operasi="hex";
            }
                else if(operasi.equalsIgnoreCase("hexa")&& operasi.equalsIgnoreCase("des")){
                int a=Integer.parseInt(j,16);
                hasil.setText(""+a);
                operasi="des";
              }
            else if(operasi.equalsIgnoreCase("hexa")&& operasi.equalsIgnoreCase("octa")){
                int a=Integer.parseInt(j,16);
                hasil.setText(""+a);
                operasi="octa";
            }
            else if(operasi.equalsIgnoreCase("hexa")&& operasi.equalsIgnoreCase("binery")){
                int a=Integer.parseInt(j,16);
                hasil.setText(""+a);
                operasi="binery";
            }
            else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("bin")){
                hasil.setText(""+Integer.toBinaryString(Integer.parseInt(j)));
                operasi1="bin";
            }  
            else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("octa")){
                hasil.setText(""+Integer.toBinaryString(Integer.parseInt(j)));
                operasi1="octa";
            }
            else if(operasi.equalsIgnoreCase("des")&& operasi1.equalsIgnoreCase("hex")){
                hasil.setText(""+Integer.toBinaryString(Integer.parseInt(j)));
                operasi1="hex";
            }
           
            }catch(NumberFormatException ab){
            hasil.setText("error");
        }
    }
    void semb(){
        if (decsa.isSelected()){
       a.setEnabled(false);
       b.setEnabled(false);
       c.setEnabled(false);
       d.setEnabled(false);
       e.setEnabled(false);
       satu.setEnabled(true);
       dua.setEnabled(true);
       tiga.setEnabled(true);
       empat.setEnabled(true);
       lima.setEnabled(true);
       enam.setEnabled(true);
       pitu.setEnabled(true);
       delapan.setEnabled(true);
       sembilan.setEnabled(true);
       nol.setEnabled(true);
       doublenol.setEnabled(true);
        }
}
    /**
     * 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();
        jPanel1 = new javax.swing.JPanel();
        hasil = new javax.swing.JTextField();
        decsa = new javax.swing.JRadioButton();
        octa = new javax.swing.JRadioButton();
        hexa = new javax.swing.JRadioButton();
        binery = new javax.swing.JRadioButton();
        satu = new javax.swing.JButton();
        dua = new javax.swing.JButton();
        tiga = new javax.swing.JButton();
        empat = new javax.swing.JButton();
        lima = new javax.swing.JButton();
        enam = new javax.swing.JButton();
        delapan = new javax.swing.JButton();
        sembilan = new javax.swing.JButton();
        dot = new javax.swing.JButton();
        nol = new javax.swing.JButton();
        samadengan = new javax.swing.JButton();
        tambah = new javax.swing.JButton();
        kurang = new javax.swing.JButton();
        kali = new javax.swing.JButton();
        doublenol = new javax.swing.JButton();
        bagi = new javax.swing.JButton();
        a = new javax.swing.JButton();
        b = new javax.swing.JButton();
        c = new javax.swing.JButton();
        d = new javax.swing.JButton();
        e = new javax.swing.JButton();
        delet = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        HAPUS = new javax.swing.JButton();
        pitu = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        hasil.setText("0");
        hasil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hasilActionPerformed(evt);
            }
        });

        buttonGroup1.add(decsa);
        decsa.setText("DEC");
        decsa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decsaActionPerformed(evt);
            }
        });

        buttonGroup1.add(octa);
        octa.setText("OCT");
        octa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                octaActionPerformed(evt);
            }
        });

        buttonGroup1.add(hexa);
        hexa.setText("HEX");
        hexa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hexaActionPerformed(evt);
            }
        });

        buttonGroup1.add(binery);
        binery.setText("BIN");
        binery.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bineryActionPerformed(evt);
            }
        });

        satu.setText("1");
        satu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                satuActionPerformed(evt);
            }
        });

        dua.setText("2");
        dua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                duaActionPerformed(evt);
            }
        });

        tiga.setText("3");
        tiga.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tigaActionPerformed(evt);
            }
        });

        empat.setText("4");
        empat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                empatActionPerformed(evt);
            }
        });

        lima.setText("5");
        lima.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limaActionPerformed(evt);
            }
        });

        enam.setText("6");
        enam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enamActionPerformed(evt);
            }
        });

        delapan.setText("8");
        delapan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delapanActionPerformed(evt);
            }
        });

        sembilan.setText("9");
        sembilan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sembilanActionPerformed(evt);
            }
        });

        dot.setText(".");
        dot.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dotActionPerformed(evt);
            }
        });

        nol.setText("0");
        nol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nolActionPerformed(evt);
            }
        });

        samadengan.setText("=");
        samadengan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                samadenganActionPerformed(evt);
            }
        });

        tambah.setText("+");
        tambah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tambahActionPerformed(evt);
            }
        });

        kurang.setText("-");
        kurang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kurangActionPerformed(evt);
            }
        });

        kali.setText("X");
        kali.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kaliActionPerformed(evt);
            }
        });

        doublenol.setText("00");
        doublenol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                doublenolActionPerformed(evt);
            }
        });

        bagi.setText("%");
        bagi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bagiActionPerformed(evt);
            }
        });

        a.setText("A");
        a.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aActionPerformed(evt);
            }
        });

        b.setText("B");
        b.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bActionPerformed(evt);
            }
        });

        c.setText("C");
        c.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cActionPerformed(evt);
            }
        });

        d.setText("D");
        d.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dActionPerformed(evt);
            }
        });

        e.setText("E");
        e.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eActionPerformed(evt);
            }
        });

        delet.setText("DEL");
        delet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deletActionPerformed(evt);
            }
        });

        jLabel1.setText("henry@calculator.com");

        jLabel2.setFont(new java.awt.Font("Vijaya", 3, 18)); // NOI18N
        jLabel2.setText("KALKULATOR");

        HAPUS.setText("C");
        HAPUS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HAPUSActionPerformed(evt);
            }
        });

        pitu.setText("7");
        pitu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pituActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(hasil, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addComponent(decsa))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(pitu, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                                    .addComponent(dot, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(empat, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(satu, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(lima, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(nol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(delapan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(doublenol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(sembilan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(enam, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(0, 0, Short.MAX_VALUE)
                                        .addComponent(dua, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(tiga, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(21, 21, 21)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(kali, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(kurang, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(tambah, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addComponent(bagi))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(c, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(d, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(b, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(a, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(octa, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(hexa)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(binery)
                                .addGap(29, 29, 29))))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(16, 16, 16)
                            .addComponent(HAPUS, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(delet, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(e, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(96, 96, 96))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(97, 97, 97))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(samadengan, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hasil, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(decsa)
                    .addComponent(octa)
                    .addComponent(hexa)
                    .addComponent(binery))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tambah)
                    .addComponent(tiga)
                    .addComponent(satu)
                    .addComponent(a, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dua))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lima)
                    .addComponent(empat)
                    .addComponent(enam)
                    .addComponent(kurang)
                    .addComponent(b))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(delapan)
                    .addComponent(pitu)
                    .addComponent(sembilan)
                    .addComponent(kali)
                    .addComponent(c))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dot)
                    .addComponent(doublenol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bagi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(d, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(HAPUS, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(delet, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(e, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(samadengan, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 31, Short.MAX_VALUE))
        );

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

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

    private void decsaActionPerformed(java.awt.event.ActionEvent evt) {                                     
   a.setEnabled(true);
       b.setEnabled(true);
       c.setEnabled(true);
       d.setEnabled(true);
       e.setEnabled(true);
       satu.setEnabled(true);
       dua.setEnabled(true);
       tiga.setEnabled(true);
       empat.setEnabled(true);
       lima.setEnabled(false);
       enam.setEnabled(false);
       pitu.setEnabled(false);
       delapan.setEnabled(false);
       sembilan.setEnabled(false);
       nol.setEnabled(false);
       doublenol.setEnabled(true);
       konvers();
       operasi1="des";
    }                                    

    private void hexaActionPerformed(java.awt.event.ActionEvent evt) {                                    
       a.setEnabled(true);
       b.setEnabled(true);
       c.setEnabled(true);
       d.setEnabled(true);
       e.setEnabled(true);
       satu.setEnabled(true);
       dua.setEnabled(true);
       tiga.setEnabled(true);
       empat.setEnabled(true);
       lima.setEnabled(true);
       enam.setEnabled(true);
       pitu.setEnabled(true);
       delapan.setEnabled(true);
       sembilan.setEnabled(true);
       nol.setEnabled(true);
       doublenol.setEnabled(false);
       operasi1="hexa";
       konvers();
    }                                   

    private void bineryActionPerformed(java.awt.event.ActionEvent evt) {                                      
    
       nol.setEnabled(true);
       satu.setEnabled(true);
       dua.setEnabled(false);
       tiga.setEnabled(false);
       empat.setEnabled(false);
       lima.setEnabled(false);
       enam.setEnabled(false);
       pitu.setEnabled(false);
       delapan.setEnabled(false);
       sembilan.setEnabled(false);
       a.setEnabled(false);
       b.setEnabled(false);
       c.setEnabled(false);
       d.setEnabled(false);
       e.setEnabled(false);
       operasi1="bin";
       konvers();
    }                                     

    private void satuActionPerformed(java.awt.event.ActionEvent evt) {                                    
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }
        if (l){
            hasil.setText("1");
            l=false;
        }else{
            hasil.setText(hasil.getText()+"1");
        }
    }                                   

    private void duaActionPerformed(java.awt.event.ActionEvent evt) {                                   
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("2");
            l=false;
        }else{
            hasil.setText(hasil.getText()+"2");
    }                                  
    }
    private void tigaActionPerformed(java.awt.event.ActionEvent evt) {                                    
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("3");
           l=false;
        }else{
            hasil.setText(hasil.getText()+"3");
        }
    }                                   

    private void empatActionPerformed(java.awt.event.ActionEvent evt) {                                     
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("4");
           l=false;
        }else{
            hasil.setText(hasil.getText()+"4");
        }
    }                                    

    private void limaActionPerformed(java.awt.event.ActionEvent evt) {                                    
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("5");
           l=false;
        }else{
            hasil.setText(hasil.getText()+"5");
        }
    }                                   

    private void enamActionPerformed(java.awt.event.ActionEvent evt) {                                    
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("6");
            l=false;
        }else{
            hasil.setText(hasil.getText()+"6");
        }
    }                                   

    private void delapanActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("8");
            l=false;
        }else{
            hasil.setText(hasil.getText()+"8");
        }
    }                                      

    private void sembilanActionPerformed(java.awt.event.ActionEvent evt) {                                        
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("9");
          l=false;
        }else{
            hasil.setText(hasil.getText()+"9");
        }
    }                                       

    private void dotActionPerformed(java.awt.event.ActionEvent evt) {                                     
        hasil.setText(hasil.getText()+dot.getText());
    }                                    

    private void nolActionPerformed(java.awt.event.ActionEvent evt) {                                   
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("0");
           l=false;
        }else{
            hasil.setText(hasil.getText()+"0");
        }
    }                                  

    private void samadenganActionPerformed(java.awt.event.ActionEvent evt) {                                          

            angka2=(Double.parseDouble(String.valueOf(hasil.getText())));
            if(plusklik>0){
                total=angka1+angka2;
                hasil.setText(String.valueOf(total));
                l=true;
                angka1=0;
                angka2=0;
                plusklik=0;
            }
            else
                if(minklik>0){
                total=angka1-angka2;
                hasil.setText(String.valueOf(total));
                l=true;
                angka1=0;
                angka2=0;
                minklik=0;
            }
            else
                    if(kaliklik>0){
                        total=angka1*angka2;
                        hasil.setText(String.valueOf(total));
                        l=true;
                        angka1=0;
                        angka2=0;
                        kaliklik=0;
                    }
            else
                        if(bagiklik>0){
                            total=angka1/angka2;
                            hasil.setText(String.valueOf(total));
                            l=true;
                            angka1=0;
                            angka2=0;
                            bagiklik=0;
                           
                        }
           
                                         
   
           // TODO add your handling code here:
    }                                         

    private void tambahActionPerformed(java.awt.event.ActionEvent evt) {                                      

      
         angka1=(Double.parseDouble(String.valueOf(hasil.getText())));
         hasil.setText("");
          plusklik=1;
          decklik=0;
          l=true;
    }                                     

    private void kurangActionPerformed(java.awt.event.ActionEvent evt) {                                      
angka1=(Double.parseDouble(String.valueOf(hasil.getText())));
          hasil.setText("");
          minklik=1;
          decklik=0;
    }                                     

    private void doublenolActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("00");
            l=false;
        }else{
            hasil.setText(hasil.getText()+"00");
        }
    }                                        

    private void aActionPerformed(java.awt.event.ActionEvent evt) {                                 
        hasil.setText(hasil.getText()+a.getText());
    }                                

    private void bActionPerformed(java.awt.event.ActionEvent evt) {                                 
        hasil.setText(hasil.getText()+b.getText());
    }                                

    private void cActionPerformed(java.awt.event.ActionEvent evt) {                                 
        hasil.setText(hasil.getText()+c.getText());
    }                                

    private void dActionPerformed(java.awt.event.ActionEvent evt) {                                 
        hasil.setText(hasil.getText()+d.getText());
    }                                

    private void eActionPerformed(java.awt.event.ActionEvent evt) {                                 
        hasil.setText(hasil.getText()+e.getText());
    }                                

    private void deletActionPerformed(java.awt.event.ActionEvent evt) {                                     
        hasil.setText(hasil.getText().substring(0,hasil.getText().length()-1));
    }                                    

    private void HAPUSActionPerformed(java.awt.event.ActionEvent evt) {                                     
        hasil.setText("0");
    }                                    

    private void octaActionPerformed(java.awt.event.ActionEvent evt) {                                    
     a.setEnabled(false);
       b.setEnabled(false);
       c.setEnabled(false);
       d.setEnabled(false);
       e.setEnabled(false);
       satu.setEnabled(true);
       dua.setEnabled(true);
       tiga.setEnabled(true);
       empat.setEnabled(true);
       lima.setEnabled(true);
       pitu.setEnabled(true);
       delapan.setEnabled(false);
       nol.setEnabled(true);
       doublenol.setEnabled(false);
       operasi1="octa";
    }                                   

    private void kaliActionPerformed(java.awt.event.ActionEvent evt) {                                    

          angka1=(Double.parseDouble(String.valueOf(hasil.getText())));
          hasil.setText("");
          kaliklik=1;
          decklik=0;        // TODO add your handling code here:
    }                                   

    private void bagiActionPerformed(java.awt.event.ActionEvent evt) {                                    
          angka1=(Double.parseDouble(String.valueOf(hasil.getText())));
          hasil.setText("");
          bagiklik=1;
          decklik=0;        // TODO add your handling code here:
    }                                   

    private void pituActionPerformed(java.awt.event.ActionEvent evt) {
      if("0".equals(hasil.getText())){
            hasil.setText("");
        }if (l){
            hasil.setText("7");
            l=false;
        }else{
            hasil.setText(hasil.getText()+"7");
        }   // 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(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new calc().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton HAPUS;
    private javax.swing.JButton a;
    private javax.swing.JButton b;
    private javax.swing.JButton bagi;
    private javax.swing.JRadioButton binery;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton c;
    private javax.swing.JButton d;
    private javax.swing.JRadioButton decsa;
    private javax.swing.JButton delapan;
    private javax.swing.JButton delet;
    private javax.swing.JButton dot;
    private javax.swing.JButton doublenol;
    private javax.swing.JButton dua;
    private javax.swing.JButton e;
    private javax.swing.JButton empat;
    private javax.swing.JButton enam;
    private javax.swing.JTextField hasil;
    private javax.swing.JRadioButton hexa;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton kali;
    private javax.swing.JButton kurang;
    private javax.swing.JButton lima;
    private javax.swing.JButton nol;
    private javax.swing.JRadioButton octa;
    private javax.swing.JButton pitu;
    private javax.swing.JButton samadengan;
    private javax.swing.JButton satu;
    private javax.swing.JButton sembilan;
    private javax.swing.JButton tambah;
    private javax.swing.JButton tiga;
    // End of variables declaration
}






share this article to: Facebook Twitter Google+ Linkedin Technorati Digg
Posted by arek informatika, Published at 15.15 and have 0 komentar

Tidak ada komentar:

Posting Komentar