Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>it is because you have just assigned the action listener to your button with this and on method you'r again assigining the action listener which is the instance of tCalculator class so when you press the button boath action listener called and 2 results are shown to you, just remove the btn1ActionPerformed method and it will work fine. try below code now................................</p> </blockquote> <pre><code>import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextField; public class Tcalculator extends JFrame implements ActionListener{ private JButton btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btnZero; private JTextField txtArea; public Tcalculator(){ btn1 = new JButton("1"); btn2 = new JButton("2"); btn3 = new JButton("3"); btn4 = new JButton("4"); btn5 = new JButton("5"); btn6 = new JButton("6"); btn7 = new JButton("7"); btn8 = new JButton("8"); btn9 = new JButton("9"); btnZero = new JButton("0"); txtArea = new JTextField(15); init(); } //performed all gui operations public void init(){ getContentPane().setLayout(new FlowLayout()); setSize(200, 200); add(txtArea); add(btn1);add(btn2); add(btn3);add(btn4); add(btn5);add(btn6); add(btn7);add(btn8); add(btn9);add(btnZero); btn1.addActionListener(this); btn2.addActionListener(this); btn3.addActionListener(this); btn4.addActionListener(this); btn5.addActionListener(this); btn6.addActionListener(this); btn7.addActionListener(this); btn8.addActionListener(this); btn9.addActionListener(this); btnZero.addActionListener(this); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } // i am using this your made function nothing changed public void actionPerformed(ActionEvent evt) { String x = txtArea.getText(); String k = evt.getActionCommand(); String a = x + k ; txtArea.setText(a); } public static void main(String args[]){ new Tcalculator(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload