title: Java - add the number or symbol to the text field when pressing a button
body: <p>I'm creating a calculator and I'm wondering how do you add number or symbol to the text field. For example when you press the button labelled '2', I want '2' to appear in the textfield.</p>
  
  <p>What I have so far is just the frame of the calculator where the buttons currently do nothing. If you need any more information, please do ask. Thanks</p>
  
  <pre><code>import javax.swing.*; 
  import java.awt.*;
  
  public class CalcFrame extends JFrame 
  {
  
      public CalcFrame()
  {
      super("Calculator");
      setLayout(new FlowLayout() );
      JTextField calcTextField = new JTextField (19);
      add (calcTextField);
      calcTextField.setEditable(false);
  
      JPanel buttonPanel = new JPanel();
      buttonPanel.setLayout ( new GridLayout(4,4) );
  
      String[] buttonNames = {"7", "8", "9", "/",
              "4", "5", "6", "*",
              "1", "2", "3", "-",
              "0", ".", "=", "+"};
  
      for (String buttonText : buttonNames)
      {
          JButton button = new JButton(buttonText);
          buttonPanel.add(button);
      }
  
      buttonPanel.setPreferredSize(new Dimension(220, 250));
      add(buttonPanel);
  
  
  }
  
  public static void main (String[]args)
      {
      CalcFrame myCalc = new CalcFrame();
      myCalc.setSize(300, 350);
      myCalc.setVisible( true );
      myCalc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  }
  }
  </code></pre>