4 Replies - 468 Views - Last Post: 02 March 2013 - 04:43 PM Rate Topic: -----

#1 kumark  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-March 13

Simple Calculator

Posted 01 March 2013 - 04:42 PM

Well a fer days ago I started doing a calculator using java (I'm still a newbie) using the Jframe, but it gave me a lot of problems. I have no idea how to show you the cade in this seccion, so I uploaded the file.

Really guys need some help to make it work

Here's the link http://www.mediafire...e2zdd7ilrzz8dlb
Is This A Good Question/Topic? 0
  • +

Replies To: Simple Calculator

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Simple Calculator

Posted 01 March 2013 - 04:46 PM

You certainly know how to copy and paste. Select your code in the editor at your end (highlight it all, CTRL-A or equivalent might work), select COPY, move your cursor to the editor window here, press the [CODE] button in the editor's tool area, place your cursor between the two code tags that appear, PASTE your code into the post. Not hard.
Was This Post Helpful? 0
  • +
  • -

#3 kumark  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-March 13

Re: Simple Calculator

Posted 02 March 2013 - 06:51 AM

Well, here it is

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

/**
 *
 * @author Horus1215
 */
public class Calc extends javax.swing.JFrame {

    float var1,var2;
    boolean sumB,restB,multB,divB;
    
    public Calc() {
        sumB=false;
        restB=false;
        multB=false;
        divB=false;
    }

    /**
     * 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() {

        BtnC1 = new javax.swing.JButton();
        BtnDiv = new javax.swing.JButton();
        BtnPtn = new javax.swing.JButton();
        BtnRes = new javax.swing.JButton();
        BtnMul = new javax.swing.JButton();
        BtnIg = new javax.swing.JButton();
        BtnSum = new javax.swing.JButton();
        BtnNm0 = new javax.swing.JButton();
        BtnC = new javax.swing.JButton();
        Lbl = new javax.swing.JTextField();
        BtnNm1 = new javax.swing.JButton();
        BtnMM = new javax.swing.JButton();
        BtnNm2 = new javax.swing.JButton();
        BtnNm9 = new javax.swing.JButton();
        BtnNm4 = new javax.swing.JButton();
        BtnNm5 = new javax.swing.JButton();
        BtnNm6 = new javax.swing.JButton();
        BtnNm3 = new javax.swing.JButton();
        BtnNm8 = new javax.swing.JButton();
        BtnNm7 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

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

        BtnDiv.setText("/");
        BtnDiv.setToolTipText("");
        BtnDiv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnDivActionPerformed(evt);
            }
        });

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

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

        BtnMul.setText("*");
        BtnMul.setToolTipText("");
        BtnMul.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnMulActionPerformed(evt);
            }
        });

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

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

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

        BtnC.setText("CE");
        BtnC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCActionPerformed(evt);
            }
        });

        Lbl.setEditable(false);
        Lbl.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        Lbl.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        Lbl.setText("0");
        Lbl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LblActionPerformed(evt);
            }
        });

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

        BtnMM.setText("+/-");
        BtnMM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnMMActionPerformed(evt);
            }
        });

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

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

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

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

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

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

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

        BtnNm7.setBackground(new java.awt.Color(255, 255, 255));
        BtnNm7.setText("7");
        BtnNm7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnNm7ActionPerformed(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()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BtnNm0, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BtnPtn, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BtnNm7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(BtnNm8, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BtnC, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(BtnC1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BtnNm9, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(BtnRes, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BtnMM, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(BtnSum, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(BtnIg, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(BtnNm4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(BtnNm5, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(BtnNm6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(BtnNm1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(BtnNm2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(BtnNm3, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(BtnMul, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(BtnDiv, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(Lbl, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Lbl, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnC1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnC, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnMM, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnSum, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnNm7, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnNm8, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnNm9, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnRes, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnNm6, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnNm5, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnNm4, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnMul, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnNm2, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnNm1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnNm3, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnDiv, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnNm0, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnIg, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BtnPtn, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

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

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

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

        divB=true;
        Lbl.setText("");
        var2=var1;
    }                                      

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

    }                                      

    private void BtnResActionPerformed(java.awt.event.ActionEvent evt) {                                       
        restB=true;
        Lbl.setText("");
        var2=var1;
    }                                      

    private void BtnMulActionPerformed(java.awt.event.ActionEvent evt) {                                       
        multB=true;
        Lbl.setText("");
        var2=var1;
    }                                      

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

        if(sumB)
        {

            Lbl.setText(String.valueOf(var1+var2));
            var1=var2+var1;
            sumB=false;

        }

        if(restB)
        {

            Lbl.setText(String.valueOf(var2-var1));
            var1=var2-var1;
            restB=false;

        }
        if(multB)
        {
            
            Lbl.setText(String.valueOf(var2*var1));
            var1=var2*var1;
            multB=false;

        }
        if(divB)
        {
            
            Lbl.setText(String.valueOf(var2/var1));
            var1=var2/var1;
            divB=false;

        }

    }                                     

    private void BtnSumActionPerformed(java.awt.event.ActionEvent evt) {                                       
        sumB=true;
        Lbl.setText("");
        sumB=false;

    }                                      

    private void BtnNm0ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("0");
        }
        else{
            Lbl.setText(Lbl.getText().concat("0"));
        }

        var1=Float.parseFloat(Lbl.getText());

    }                                      

    private void BtnCActionPerformed(java.awt.event.ActionEvent evt) {                                     
        Lbl.setText("0");
        var1=0;
        var2=0;
        multB=false;
        divB=false;
        sumB=false;
        restB=false;

    }                                    

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

        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("1");
        }
        else{
            Lbl.setText(Lbl.getText().concat("1"));
        }

        var1=Float.parseFloat(Lbl.getText());

    }                                      

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

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

        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("2");
        }
        else{
            Lbl.setText(Lbl.getText().concat("2"));
        }

        var1=Float.parseFloat(Lbl.getText());
        

    }                                      

    private void BtnNm9ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("9");
        }
        else{
            Lbl.setText(Lbl.getText().concat("9"));
        }
        var1=Float.parseFloat(Lbl.getText());
    }                                      

    private void BtnNm4ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("4");
        }
        else{
            Lbl.setText(Lbl.getText().concat("4"));
        }
        var1=Float.parseFloat(Lbl.getText());
    }                                      

    private void BtnNm5ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("5");
        }
        else{
            Lbl.setText(Lbl.getText().concat("5"));
        }
        var1=Float.parseFloat(Lbl.getText());
    }                                      

    private void BtnNm6ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("6");
        }
        else{
            Lbl.setText(Lbl.getText().concat("6"));
        }
    }                                      

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

        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("3");
        }
        else{
            Lbl.setText(Lbl.getText().concat("3"));
        }
        var1=Float.parseFloat(Lbl.getText());
    }                                      

    private void BtnNm8ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("8");
        }
        else{
            Lbl.setText(Lbl.getText().concat("8"));
        }
        var1=Float.parseFloat(Lbl.getText());
    }                                      

    private void BtnNm7ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        if(Lbl.getText().equals("0") || Lbl.getText().equals("")){
            Lbl.setText("7");
        }
        else{
            Lbl.setText(Lbl.getText().concat("7"));
        }
        var1=Float.parseFloat(Lbl.getText());
    }                                      

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(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() {
            public void run() {
                new Calc().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton BtnC;
    private javax.swing.JButton BtnC1;
    private javax.swing.JButton BtnDiv;
    private javax.swing.JButton BtnIg;
    private javax.swing.JButton BtnMM;
    private javax.swing.JButton BtnMul;
    private javax.swing.JButton BtnNm0;
    private javax.swing.JButton BtnNm1;
    private javax.swing.JButton BtnNm2;
    private javax.swing.JButton BtnNm3;
    private javax.swing.JButton BtnNm4;
    private javax.swing.JButton BtnNm5;
    private javax.swing.JButton BtnNm6;
    private javax.swing.JButton BtnNm7;
    private javax.swing.JButton BtnNm8;
    private javax.swing.JButton BtnNm9;
    private javax.swing.JButton BtnPtn;
    private javax.swing.JButton BtnRes;
    private javax.swing.JButton BtnSum;
    private javax.swing.JTextField Lbl;
    // End of variables declaration                   
}




Was This Post Helpful? 0
  • +
  • -

#4 k3y  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 205
  • Joined: 25-February 12

Re: Simple Calculator

Posted 02 March 2013 - 04:39 PM

I can tell that you used NetBeansIDE GUI builder, which is okay to get your functionality working, however; I'd suggest that you delete a majority of that auto-generated code(dealing with the layout and such). Also, a general tip for cleaning up that code as a whole, a line like
BtnC1 = new javax.swing.JButton();


can be cleaned up by simply importing
import javax.swing.JButton;


Then you can simply say:
JButton btnC1 = new JButton();


Also your naming conventions seem to be strange: http://java.about.co...conventions.htm
I'd suggest that you do that, get rid of the GUI code (it's way to messy), and, then repost.

EDIT: to get ideas please research your question:
http://stackoverflow...java-calculator

This post has been edited by k3y: 02 March 2013 - 04:56 PM

Was This Post Helpful? 1
  • +
  • -

#5 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Simple Calculator

Posted 02 March 2013 - 04:43 PM

Notice this comment (starting at line 23):
    /**
     * 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() {

Look at your constructor. Is the method initComponents() called from the constructor as the note indicates? What happens if it is?

You really should learn to code basic Swing GUIs "by hand" so that you understand the basics of building a user interface, displaying it, and programming it to react correctly to user input. Though this particular problem may be due to a lack of foundational knowledge. Before writing GUI programs, you should learn the basic elements of the typical Java program and OOP concepts.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1