title: Calculator with two lines text field in Java
body: <p>I am trying to make a calculator in Java GUI classes that has the following properties: </p>
  
  <ol>
  <li>The Text field where the opertations occur must be composed of two lines
  Line 1 to print the operation we do
  Line 2 to print the resut of the operation</li>
  <li>The buttons of the calclator have to be organized in the way shown in the down figure:
  <a href="https://i.stack.imgur.com/QDgP5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QDgP5.jpg" alt="enter image description here"></a></li>
  </ol>
  
  <p>Using the GridLayout and BorderLayout layout managers I couldnt get the desired result
  How can this be solved ? </p>
  
  <p>The code I wrote is below</p>
  
  <pre><code>import java.awt.GridLayout;
  import java.awt.BorderLayout;
  
  import javax.swing.*;
  
  import java.awt.Font;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  public class calculator {
      public static JTextField field;
      public static String pStr="";
      // Create an array containing the buttons texts
      public static final String[][] BUTTON_TEXTS = {
              {" ", " ", "d", " c"},
              {"7", "8", "9", "+"},
              {"4", "5", "6", "-"},
              {"1", "2", "3", "*"},
              {"0", ".", "/", "="}
      };
      // Create the button hnadler 
      private static class ButtonHandler implements ActionListener{
          private static int clicksNumber = 0;
          private String c;
  
           public void numberButtonsAction(JButton a) {
                  this.c = a.getText();
              }
          public void actionPerformed(ActionEvent e){
  
              clicksNumber ++ ;
              pStr +=((JButton) e.getSource()).getText();
              System.out.println(pStr);
              field.setText(pStr);
          }
      }
      //Create Font used in caluclator
      public static final Font BTN_FONT = new Font(Font.SANS_SERIF, Font.ITALIC, 15);
      public static void main(String[] args){
  
          // create the field in which the operations are printed
          JTextField text = new JTextField();
          text.setSize(20, 500);
          field = text;
          text.setFont(BTN_FONT); // Set the field font
          JLabel myLabel = new JLabel("Se7002");
  
          // Create the grid that will contain the buttons
          JPanel btnPanel = new JPanel(new GridLayout(BUTTON_TEXTS.length,
                  BUTTON_TEXTS[0].length));
  
          // Create and Fill grid with buttons
          for(int i=0  ;i&lt;BUTTON_TEXTS.length ; i++){
              for(int j=0 ; j&lt; BUTTON_TEXTS[0].length ; j++){
                  JButton btn = new JButton(BUTTON_TEXTS[i][j]);
                  btn.setFont(BTN_FONT);
                  btn.setSize(60,90);
                  btnPanel.add(btn);
                  ButtonHandler listener = new ButtonHandler();
                  btn.addActionListener(listener);
              }
          }
  
          //Create the content of the calculator 
          JPanel content =  new JPanel(new BorderLayout());
          content.add(text,BorderLayout.PAGE_START);
          content.add(btnPanel,BorderLayout.CENTER);
          content.add(myLabel,BorderLayout.SOUTH);
  
  
  
          JFrame CalcTest = new JFrame("Calculator");
          CalcTest.setContentPane(content);
          CalcTest.setSize(300,350);
          CalcTest.setLocation(100, 100);
          CalcTest.setVisible(true);
      }
  
  }
  </code></pre>