Hello I'm a vb.net programmer and I am learning java so I was trying to figure out what is "sender" (VB.net) keyword in java?

sender is simply a keyword in VB.net, for example you have multiple buttons having the same event and the code but you differentiate them in the code bythe sender keyword.
For example Label1.setText(sender.gettext());

Thanks.

When you handle a GUI event in Java there is an Event object passed to your handler. The event object has a getSource() method that returns the object that generated the event. Eg in an Action listener (responds to button presses and the like) you provide a handler method with this signature

public void actionPerformed(ActionEvent arg0)

in which you can call

arg0.getSource()

to return the source object (JButton or whatever)
Similar classes and methods exist for every kind of GUI event

so why do I have to check for the buttons always with if (arg0.getSource() == btn1) ... while when I try to use txtNumberF.setText(e.getSource().gettext); it doesn't work.

One reason you have to test (arg0.getSource() == btn1) is because you are using one ActionListener for all your components. This is a common thing in beginners code, where they just put one actionPerformed in their main class and use that as the listener for all their components.
More advanced programmes are more likely to use multiple inner classes to define individual listeners for each component, so there's no need to test the source. The real pros use java Actions http://download.oracle.com/javase/tutorial/uiswing/misc/action.html

e.getSource().gettext) (assuming you fix the typos) won't work because getSource() returns an Object, and the Object class doesn't have a getText() method. Assuming that you know that the source is a GUI component, you can cast the returned value to make that work, eg
((JButton) e.getSource()).getText()

Edited 5 Years Ago by JamesCherrill: Fix typos, clarify.

So why this code isn't working?

public void actionPerformed(ActionEvent e) {
        if (flag == true) {
            oldValue = Double.parseDouble(txtNumberF.getText());
            txtNumberF.setText("");
            flag = false;
        }
            txtNumberF.setText(txtNumberF.getText() + ((JButton) e.getSource()).getText());
      

    }

I dunno. Exactly what are the symptoms of it "not working"?

ps if (flag == true) is a redundant way to write if (flag) The difference is even greater if the boolean has a proper descriptive name, eg if (fieldMustBeCleared)

even if I remove the if(flag) the actionperformed itself doesn't work

package Calculator;

import com.sun.org.apache.bcel.internal.generic.Select;
import java.awt.Button;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class gui1 extends javax.swing.JFrame {

    boolean flag;
    double oldValue;
    String operation;
    boolean DotCheck;
    boolean CheckEqual;
    double AnswerAfterEqual;

    /** Creates new form gui1 */
    public gui1() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        btn0 = new javax.swing.JButton();
        btnPlus = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        btnMin = new javax.swing.JButton();
        btnMultiply = new javax.swing.JButton();
        btn6 = new javax.swing.JButton();
        btnDivide = new javax.swing.JButton();
        btn9 = new javax.swing.JButton();
        btn3 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();
        btn7 = new javax.swing.JButton();
        btn5 = new javax.swing.JButton();
        btn1 = new javax.swing.JButton();
        btn4 = new javax.swing.JButton();
        txtNumberF = new javax.swing.JTextField();
        btn2 = new javax.swing.JButton();
        btn8 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(networkingServer.NetworkingApp.class).getContext().getResourceMap(gui1.class);
        btn0.setForeground(resourceMap.getColor("btn0.foreground")); // NOI18N
        btn0.setText(resourceMap.getString("btn0.text")); // NOI18N
        btn0.setName("btn0"); // NOI18N

        btnPlus.setForeground(resourceMap.getColor("btnPlus.foreground")); // NOI18N
        btnPlus.setText(resourceMap.getString("btnPlus.text")); // NOI18N
        btnPlus.setName("btnPlus"); // NOI18N

        jButton14.setForeground(resourceMap.getColor("jButton14.foreground")); // NOI18N
        jButton14.setText(resourceMap.getString("jButton14.text")); // NOI18N
        jButton14.setName("jButton14"); // NOI18N

        btnMin.setForeground(resourceMap.getColor("btnMin.foreground")); // NOI18N
        btnMin.setText(resourceMap.getString("btnMin.text")); // NOI18N
        btnMin.setName("btnMin"); // NOI18N

        btnMultiply.setForeground(resourceMap.getColor("btnMultiply.foreground")); // NOI18N
        btnMultiply.setText(resourceMap.getString("btnMultiply.text")); // NOI18N
        btnMultiply.setName("btnMultiply"); // NOI18N

        btn6.setForeground(resourceMap.getColor("btn6.foreground")); // NOI18N
        btn6.setText(resourceMap.getString("btn6.text")); // NOI18N
        btn6.setName("btn6"); // NOI18N

        btnDivide.setForeground(resourceMap.getColor("btnDivide.foreground")); // NOI18N
        btnDivide.setText(resourceMap.getString("btnDivide.text")); // NOI18N
        btnDivide.setName("btnDivide"); // NOI18N

        btn9.setForeground(resourceMap.getColor("btn9.foreground")); // NOI18N
        btn9.setText(resourceMap.getString("btn9.text")); // NOI18N
        btn9.setName("btn9"); // NOI18N

        btn3.setForeground(resourceMap.getColor("btn3.foreground")); // NOI18N
        btn3.setText(resourceMap.getString("btn3.text")); // NOI18N
        btn3.setName("btn3"); // NOI18N

        jButton16.setForeground(resourceMap.getColor("jButton16.foreground")); // NOI18N
        jButton16.setText(resourceMap.getString("jButton16.text")); // NOI18N
        jButton16.setName("jButton16"); // NOI18N

        btn7.setForeground(resourceMap.getColor("btn7.foreground")); // NOI18N
        btn7.setText(resourceMap.getString("btn7.text")); // NOI18N
        btn7.setName("btn7"); // NOI18N

        btn5.setForeground(resourceMap.getColor("btn5.foreground")); // NOI18N
        btn5.setText(resourceMap.getString("btn5.text")); // NOI18N
        btn5.setName("btn5"); // NOI18N

        btn1.setForeground(resourceMap.getColor("btn1.foreground")); // NOI18N
        btn1.setText(resourceMap.getString("btn1.text")); // NOI18N
        btn1.setName("btn1"); // NOI18N

        btn4.setForeground(resourceMap.getColor("btn4.foreground")); // NOI18N
        btn4.setText(resourceMap.getString("btn4.text")); // NOI18N
        btn4.setName("btn4"); // NOI18N

        txtNumberF.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtNumberF.setName("txtNumberF"); // NOI18N

        btn2.setForeground(resourceMap.getColor("btn2.foreground")); // NOI18N
        btn2.setText(resourceMap.getString("btn2.text")); // NOI18N
        btn2.setName("btn2"); // NOI18N

        btn8.setForeground(resourceMap.getColor("btn8.foreground")); // NOI18N
        btn8.setText(resourceMap.getString("btn8.text")); // NOI18N
        btn8.setName("btn8"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 228, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(btn0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jButton16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btnPlus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btn1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btn2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btn3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btnMin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btnMultiply, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btnDivide, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, txtNumberF)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jButton14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 228, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(txtNumberF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(btn7)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn1))
                    .add(layout.createSequentialGroup()
                        .add(btn8)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn5)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn2))
                    .add(layout.createSequentialGroup()
                        .add(btn9)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(btn3)
                            .add(btnMin)))
                    .add(layout.createSequentialGroup()
                        .add(btnDivide)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btnMultiply)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(btn0)
                    .add(btnPlus)
                    .add(jButton16))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton14)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

    /**
     * @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(gui1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(gui1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(gui1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(gui1.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 gui1().setVisible(true);
            }
        });
    }

    public void actionPerformed(ActionEvent e) {
       /* if (flag) {
            oldValue = Double.parseDouble(txtNumberF.getText());
            txtNumberF.setText("");
            flag = false;
        }*/
            txtNumberF.setText(txtNumberF.getText() + ((JButton) e.getSource()).getText());
            JOptionPane.showMessageDialog(null, "Helooo");
        
        
           
      

    }
    // Variables declaration - do not modify
    private javax.swing.JButton btn0;
    private javax.swing.JButton btn1;
    private javax.swing.JButton btn2;
    private javax.swing.JButton btn3;
    private javax.swing.JButton btn4;
    private javax.swing.JButton btn5;
    private javax.swing.JButton btn6;
    private javax.swing.JButton btn7;
    private javax.swing.JButton btn8;
    private javax.swing.JButton btn9;
    private javax.swing.JButton btnDivide;
    private javax.swing.JButton btnMin;
    private javax.swing.JButton btnMultiply;
    private javax.swing.JButton btnPlus;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton16;
    private javax.swing.JTextField txtNumberF;
    // End of variables declaration
}

the message dialog is just for testing and it doesn't pop up.

even if I remove the if(flag) the actionperformed itself doesn't work

package Calculator;

import com.sun.org.apache.bcel.internal.generic.Select;
import java.awt.Button;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class gui1 extends javax.swing.JFrame {

    boolean flag;
    double oldValue;
    String operation;
    boolean DotCheck;
    boolean CheckEqual;
    double AnswerAfterEqual;

    /** Creates new form gui1 */
    public gui1() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        btn0 = new javax.swing.JButton();
        btnPlus = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        btnMin = new javax.swing.JButton();
        btnMultiply = new javax.swing.JButton();
        btn6 = new javax.swing.JButton();
        btnDivide = new javax.swing.JButton();
        btn9 = new javax.swing.JButton();
        btn3 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();
        btn7 = new javax.swing.JButton();
        btn5 = new javax.swing.JButton();
        btn1 = new javax.swing.JButton();
        btn4 = new javax.swing.JButton();
        txtNumberF = new javax.swing.JTextField();
        btn2 = new javax.swing.JButton();
        btn8 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(networkingServer.NetworkingApp.class).getContext().getResourceMap(gui1.class);
        btn0.setForeground(resourceMap.getColor("btn0.foreground")); // NOI18N
        btn0.setText(resourceMap.getString("btn0.text")); // NOI18N
        btn0.setName("btn0"); // NOI18N

        btnPlus.setForeground(resourceMap.getColor("btnPlus.foreground")); // NOI18N
        btnPlus.setText(resourceMap.getString("btnPlus.text")); // NOI18N
        btnPlus.setName("btnPlus"); // NOI18N

        jButton14.setForeground(resourceMap.getColor("jButton14.foreground")); // NOI18N
        jButton14.setText(resourceMap.getString("jButton14.text")); // NOI18N
        jButton14.setName("jButton14"); // NOI18N

        btnMin.setForeground(resourceMap.getColor("btnMin.foreground")); // NOI18N
        btnMin.setText(resourceMap.getString("btnMin.text")); // NOI18N
        btnMin.setName("btnMin"); // NOI18N

        btnMultiply.setForeground(resourceMap.getColor("btnMultiply.foreground")); // NOI18N
        btnMultiply.setText(resourceMap.getString("btnMultiply.text")); // NOI18N
        btnMultiply.setName("btnMultiply"); // NOI18N

        btn6.setForeground(resourceMap.getColor("btn6.foreground")); // NOI18N
        btn6.setText(resourceMap.getString("btn6.text")); // NOI18N
        btn6.setName("btn6"); // NOI18N

        btnDivide.setForeground(resourceMap.getColor("btnDivide.foreground")); // NOI18N
        btnDivide.setText(resourceMap.getString("btnDivide.text")); // NOI18N
        btnDivide.setName("btnDivide"); // NOI18N

        btn9.setForeground(resourceMap.getColor("btn9.foreground")); // NOI18N
        btn9.setText(resourceMap.getString("btn9.text")); // NOI18N
        btn9.setName("btn9"); // NOI18N

        btn3.setForeground(resourceMap.getColor("btn3.foreground")); // NOI18N
        btn3.setText(resourceMap.getString("btn3.text")); // NOI18N
        btn3.setName("btn3"); // NOI18N

        jButton16.setForeground(resourceMap.getColor("jButton16.foreground")); // NOI18N
        jButton16.setText(resourceMap.getString("jButton16.text")); // NOI18N
        jButton16.setName("jButton16"); // NOI18N

        btn7.setForeground(resourceMap.getColor("btn7.foreground")); // NOI18N
        btn7.setText(resourceMap.getString("btn7.text")); // NOI18N
        btn7.setName("btn7"); // NOI18N

        btn5.setForeground(resourceMap.getColor("btn5.foreground")); // NOI18N
        btn5.setText(resourceMap.getString("btn5.text")); // NOI18N
        btn5.setName("btn5"); // NOI18N

        btn1.setForeground(resourceMap.getColor("btn1.foreground")); // NOI18N
        btn1.setText(resourceMap.getString("btn1.text")); // NOI18N
        btn1.setName("btn1"); // NOI18N

        btn4.setForeground(resourceMap.getColor("btn4.foreground")); // NOI18N
        btn4.setText(resourceMap.getString("btn4.text")); // NOI18N
        btn4.setName("btn4"); // NOI18N

        txtNumberF.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtNumberF.setName("txtNumberF"); // NOI18N

        btn2.setForeground(resourceMap.getColor("btn2.foreground")); // NOI18N
        btn2.setText(resourceMap.getString("btn2.text")); // NOI18N
        btn2.setName("btn2"); // NOI18N

        btn8.setForeground(resourceMap.getColor("btn8.foreground")); // NOI18N
        btn8.setText(resourceMap.getString("btn8.text")); // NOI18N
        btn8.setName("btn8"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 228, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(btn0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jButton16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btnPlus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btn1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btn2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btn3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btn9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(btnMin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btnMultiply, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btnDivide, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, txtNumberF)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jButton14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 228, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(txtNumberF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(btn7)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn1))
                    .add(layout.createSequentialGroup()
                        .add(btn8)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn5)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn2))
                    .add(layout.createSequentialGroup()
                        .add(btn9)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btn6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(btn3)
                            .add(btnMin)))
                    .add(layout.createSequentialGroup()
                        .add(btnDivide)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btnMultiply)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(btn0)
                    .add(btnPlus)
                    .add(jButton16))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton14)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

    /**
     * @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(gui1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(gui1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(gui1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(gui1.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 gui1().setVisible(true);
            }
        });
    }

    public void actionPerformed(ActionEvent e) {
       /* if (flag) {
            oldValue = Double.parseDouble(txtNumberF.getText());
            txtNumberF.setText("");
            flag = false;
        }*/
            txtNumberF.setText(txtNumberF.getText() + ((JButton) e.getSource()).getText());
            JOptionPane.showMessageDialog(null, "Helooo");
        
        
           
      

    }
    // Variables declaration - do not modify
    private javax.swing.JButton btn0;
    private javax.swing.JButton btn1;
    private javax.swing.JButton btn2;
    private javax.swing.JButton btn3;
    private javax.swing.JButton btn4;
    private javax.swing.JButton btn5;
    private javax.swing.JButton btn6;
    private javax.swing.JButton btn7;
    private javax.swing.JButton btn8;
    private javax.swing.JButton btn9;
    private javax.swing.JButton btnDivide;
    private javax.swing.JButton btnMin;
    private javax.swing.JButton btnMultiply;
    private javax.swing.JButton btnPlus;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton16;
    private javax.swing.JTextField txtNumberF;
    // End of variables declaration
}

the message dialog is just for testing and it doesn't pop up.

This question has already been answered. Start a new discussion instead.