Alif Satrio / 2012420117

Alif Satrio / 2012420117

public class Calculator extends javax.swing.JFrame {

    String bil="";
    int pilihan;
    double bil1, bil2, hasil;
    /** Creates new form Calculator */
    public Calculator() {
        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();
        jPanel1 = new javax.swing.JPanel();
        Layar = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        Button7 = new javax.swing.JToggleButton();
        Button8 = new javax.swing.JToggleButton();
        Button9 = new javax.swing.JToggleButton();
        Bagi = new javax.swing.JToggleButton();
        Button4 = new javax.swing.JToggleButton();
        Button5 = new javax.swing.JToggleButton();
        Button6 = new javax.swing.JToggleButton();
        jToggleButtonKali = new javax.swing.JToggleButton();
        Button1 = new javax.swing.JToggleButton();
        Button2 = new javax.swing.JToggleButton();
        Button3 = new javax.swing.JToggleButton();
        jToggleButtonMinus = new javax.swing.JToggleButton();
        Button0 = new javax.swing.JToggleButton();
        jToggleButtonKoma = new javax.swing.JToggleButton();
        SamaDengan = new javax.swing.JToggleButton();
        jToggleButtonTambah = new javax.swing.JToggleButton();
        Modulus = new javax.swing.JToggleButton();
        Clear = new javax.swing.JToggleButton();
        AC = new javax.swing.JToggleButton();
        End = new javax.swing.JToggleButton();
        Pangkat = new javax.swing.JToggleButton();
        Pangkat2 = new javax.swing.JToggleButton();
        Biner = new javax.swing.JRadioButton();
        Oktal = new javax.swing.JRadioButton();
        Hexa = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("AlifSatrio/2012420117");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        Layar.setBackground(new java.awt.Color(255, 51, 153));
        Layar.setFont(new java.awt.Font("Monotype Corsiva", 1, 36));
        Layar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LayarActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 51, 153));

        Button7.setBackground(new java.awt.Color(255, 255, 255));
        Button7.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button7.setForeground(new java.awt.Color(255, 51, 153));
        Button7.setText("7");
        Button7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button7ActionPerformed(evt);
            }
        });

        Button8.setBackground(new java.awt.Color(255, 255, 255));
        Button8.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button8.setForeground(new java.awt.Color(255, 51, 153));
        Button8.setText("8");
        Button8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button8ActionPerformed(evt);
            }
        });

        Button9.setBackground(new java.awt.Color(255, 255, 255));
        Button9.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button9.setForeground(new java.awt.Color(255, 51, 153));
        Button9.setText("9");
        Button9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button9ActionPerformed(evt);
            }
        });

        Bagi.setBackground(new java.awt.Color(255, 255, 255));
        Bagi.setFont(new java.awt.Font("Tahoma", 1, 11));
        Bagi.setForeground(new java.awt.Color(255, 51, 153));
        Bagi.setText(":");
        Bagi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BagiActionPerformed(evt);
            }
        });

        Button4.setBackground(new java.awt.Color(255, 255, 255));
        Button4.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button4.setForeground(new java.awt.Color(255, 51, 153));
        Button4.setText("4");
        Button4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button4ActionPerformed(evt);
            }
        });

        Button5.setBackground(new java.awt.Color(255, 255, 255));
        Button5.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button5.setForeground(new java.awt.Color(255, 51, 153));
        Button5.setText("5");
        Button5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button5ActionPerformed(evt);
            }
        });

        Button6.setBackground(new java.awt.Color(255, 255, 255));
        Button6.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button6.setForeground(new java.awt.Color(255, 51, 153));
        Button6.setText("6");
        Button6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button6ActionPerformed(evt);
            }
        });

        jToggleButtonKali.setBackground(new java.awt.Color(255, 255, 255));
        jToggleButtonKali.setFont(new java.awt.Font("Tahoma", 1, 11));
        jToggleButtonKali.setForeground(new java.awt.Color(255, 51, 153));
        jToggleButtonKali.setText("x");
        jToggleButtonKali.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonKaliActionPerformed(evt);
            }
        });

        Button1.setBackground(new java.awt.Color(255, 255, 255));
        Button1.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button1.setForeground(new java.awt.Color(255, 51, 153));
        Button1.setText("1");
        Button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button1ActionPerformed(evt);
            }
        });

        Button2.setBackground(new java.awt.Color(255, 255, 255));
        Button2.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button2.setForeground(new java.awt.Color(255, 51, 153));
        Button2.setText("2");
        Button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button2ActionPerformed(evt);
            }
        });

        Button3.setBackground(new java.awt.Color(255, 255, 255));
        Button3.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button3.setForeground(new java.awt.Color(255, 51, 153));
        Button3.setText("3");
        Button3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button3ActionPerformed(evt);
            }
        });

        jToggleButtonMinus.setBackground(new java.awt.Color(255, 255, 255));
        jToggleButtonMinus.setFont(new java.awt.Font("Tahoma", 1, 11));
        jToggleButtonMinus.setForeground(new java.awt.Color(255, 51, 153));
        jToggleButtonMinus.setText("-");
        jToggleButtonMinus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonMinusActionPerformed(evt);
            }
        });

        Button0.setBackground(new java.awt.Color(255, 255, 255));
        Button0.setFont(new java.awt.Font("Tahoma", 1, 11));
        Button0.setForeground(new java.awt.Color(255, 51, 153));
        Button0.setText("0");
        Button0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Button0ActionPerformed(evt);
            }
        });

        jToggleButtonKoma.setBackground(new java.awt.Color(255, 255, 255));
        jToggleButtonKoma.setFont(new java.awt.Font("Tahoma", 1, 11));
        jToggleButtonKoma.setForeground(new java.awt.Color(255, 51, 153));
        jToggleButtonKoma.setText(".");
        jToggleButtonKoma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonKomaActionPerformed(evt);
            }
        });

        SamaDengan.setBackground(new java.awt.Color(255, 255, 255));
        SamaDengan.setFont(new java.awt.Font("Tahoma", 1, 11));
        SamaDengan.setForeground(new java.awt.Color(255, 51, 153));
        SamaDengan.setText("=");
        SamaDengan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SamaDenganActionPerformed(evt);
            }
        });

        jToggleButtonTambah.setBackground(new java.awt.Color(255, 255, 255));
        jToggleButtonTambah.setFont(new java.awt.Font("Tahoma", 1, 11));
        jToggleButtonTambah.setForeground(new java.awt.Color(255, 51, 153));
        jToggleButtonTambah.setText("+");
        jToggleButtonTambah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonTambahActionPerformed(evt);
            }
        });

        Modulus.setBackground(new java.awt.Color(255, 255, 255));
        Modulus.setFont(new java.awt.Font("Tahoma", 1, 10));
        Modulus.setForeground(new java.awt.Color(255, 51, 153));
        Modulus.setText("Mod");
        Modulus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ModulusActionPerformed(evt);
            }
        });

        Clear.setBackground(new java.awt.Color(255, 255, 255));
        Clear.setFont(new java.awt.Font("Tahoma", 1, 10));
        Clear.setForeground(new java.awt.Color(255, 51, 153));
        Clear.setText("C");
        Clear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearActionPerformed(evt);
            }
        });

        AC.setBackground(new java.awt.Color(255, 255, 255));
        AC.setFont(new java.awt.Font("Tahoma", 1, 10));
        AC.setForeground(new java.awt.Color(255, 51, 153));
        AC.setText("AC");
        AC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ACActionPerformed(evt);
            }
        });

        End.setBackground(new java.awt.Color(255, 255, 255));
        End.setFont(new java.awt.Font("Tahoma", 1, 10));
        End.setForeground(new java.awt.Color(255, 51, 153));
        End.setText("END");
        End.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EndActionPerformed(evt);
            }
        });

        Pangkat.setBackground(new java.awt.Color(255, 255, 255));
        Pangkat.setFont(new java.awt.Font("Times New Roman", 1, 11));
        Pangkat.setForeground(new java.awt.Color(255, 51, 153));
        Pangkat.setText("X^2");
        Pangkat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PangkatActionPerformed(evt);
            }
        });

        Pangkat2.setBackground(new java.awt.Color(255, 255, 255));
        Pangkat2.setFont(new java.awt.Font("Tahoma", 1, 10));
        Pangkat2.setForeground(new java.awt.Color(255, 51, 153));
        Pangkat2.setText("X^y");
        Pangkat2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Pangkat2ActionPerformed(evt);
            }
        });

        Biner.setBackground(new java.awt.Color(255, 51, 153));
        buttonGroup1.add(Biner);
        Biner.setFont(new java.awt.Font("Tempus Sans ITC", 1, 10));
        Biner.setText("Binary");
        Biner.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BinerActionPerformed(evt);
            }
        });

        Oktal.setBackground(new java.awt.Color(255, 51, 153));
        buttonGroup1.add(Oktal);
        Oktal.setFont(new java.awt.Font("Tempus Sans ITC", 1, 10));
        Oktal.setText("Octal");
        Oktal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OktalActionPerformed(evt);
            }
        });

        Hexa.setBackground(new java.awt.Color(255, 51, 153));
        buttonGroup1.add(Hexa);
        Hexa.setFont(new java.awt.Font("Tempus Sans ITC", 1, 10));
        Hexa.setText("Hexa");
        Hexa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HexaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(Button7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Button8, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Button9, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Bagi, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Pangkat, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(Button4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Button5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Button6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToggleButtonKali, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Pangkat2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(Button1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Button2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Button3, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToggleButtonMinus, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Biner))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(Button0, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToggleButtonKoma, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SamaDengan, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jToggleButtonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Oktal))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(Modulus, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Clear, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(AC, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(End, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Hexa)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Button7, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button8, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button9, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Bagi, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Pangkat, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Button4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button5, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button6, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButtonKali, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Pangkat2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Button1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Button3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButtonMinus, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Biner))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Button0, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButtonKoma, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SamaDengan, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButtonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Oktal))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Modulus, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Clear, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AC, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(End, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Hexa))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Layar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Layar, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

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

    private void Button7ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        bil += "7";
        Layar.setText(bil);
    }                                      

    private void Button8ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="8";
        Layar.setText(bil);
    }                                      

    private void Button9ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="9";
        Layar.setText(bil);
    }                                      

    private void BagiActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        bil1=Double.parseDouble(bil);
        bil="";
        pilihan=1;
    }                                   

    private void Button4ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="4";
        Layar.setText(bil);
    }                                      

    private void Button5ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="5";
        Layar.setText(bil);
    }                                      

    private void Button6ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="6";
        Layar.setText(bil);
    }                                      

    private void jToggleButtonKaliActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:
       bil1=Double.parseDouble(bil);
       bil="";
       pilihan=2;
    }                                                

    private void Button1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="1";
        Layar.setText(bil);
    }                                      

    private void Button2ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="2";
        Layar.setText(bil);
    }                                      

    private void Button3ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="3";
        Layar.setText(bil);
    }                                      

    private void jToggleButtonMinusActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        // TODO add your handling code here:
        bil1=Double.parseDouble(bil);
        bil="";
        pilihan=3;
    }                                                 

    private void Button0ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil +="0";
        Layar.setText(bil);
    }                                      

    private void jToggleButtonKomaActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:
        bil +=".";
        Layar.setText(bil);
    }                                                

    private void SamaDenganActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        switch(pilihan){
            case 1:
                bil2=Double.parseDouble(bil);
                hasil=bil1/bil2;
                bil=Double.toString(hasil);
                Layar.setText(bil);
                break;
            case 2:
                bil2=Double.parseDouble(bil);
                hasil=bil1*bil2;
                bil=Double.toString(hasil);
                Layar.setText(bil);
                break;
            case 3:
                 bil2=Double.parseDouble(bil);
                hasil=bil1-bil2;
                bil=Double.toString(hasil);
                Layar.setText(bil);
                break;
            case 4:
                 bil2=Double.parseDouble(bil);
                hasil=bil1+bil2;
                bil=Double.toString(hasil);
                Layar.setText(bil);
                break;
            case 5:
                 bil2=Double.parseDouble(bil);
                hasil=bil1%bil2;
                bil=Double.toString(hasil);
                Layar.setText(bil);
                break;
                 case 6:
                bil2=Double.parseDouble(bil);
                hasil=Math.pow(bil1, bil2);
                bil=Double.toString(hasil);
                Layar.setText(bil);
                break;
                 case 7:
//                    String a=Layar.getText();
                    Layar.setText(Integer.toBinaryString(Integer.parseInt(bil)));
                    bil="";
                     break;
                     case 8:
                         String b=Layar.getText();
                    Layar.setText(Integer.toOctalString(Integer.parseInt(b)));
                    bil="";
                     break;
                     case 9:
                         String c=Layar.getText();
                    Layar.setText(Integer.toHexString(Integer.parseInt(c)));
                    bil="";
                     break;
                default:
                    break;
        }
               
    }                                         

    private void jToggleButtonTambahActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
        bil1=Double.parseDouble(bil);
        bil="";
        pilihan=4;
    }                                                  

    private void ModulusActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil1=Double.parseDouble(bil);
        bil="";
        pilihan=5;
    }                                      

    private void ClearActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        String a=Layar.getText();
        bil=a.substring(0,a.length()-1);
        Layar.setText(bil);
    }                                    

    private void ACActionPerformed(java.awt.event.ActionEvent evt) {                                  
        // TODO add your handling code here:
        bil="";
        bil1=0;
        bil2=0;
        hasil=0;
        Layar.setText("");
    }                                 

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

    private void PangkatActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        bil1=Double.parseDouble(bil);
        bil="";
        hasil=Math.pow(bil1,2);
        bil=Double.toString(hasil);
        Layar.setText(bil);
    }                                      

    private void Pangkat2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        bil1=Double.parseDouble(bil);
        bil="";
        pilihan=6;
    }                                       

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

    private void BinerActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        pilihan=7;
    }                                    

    private void OktalActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        pilihan=8;
    }                                    

    private void HexaActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        pilihan=9;
    }                                   

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

            public void run() {
                new Calculator().setVisible(true);
            }
        });
    }










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

Tidak ada komentar:

Posting Komentar