import java.awt.*;
import javax.swing.*;

/** Displays a window containing a couple fields and buttons. */
public class SimpleFieldDemo2 {

  public static void main(String[] args) {
    JFrame frame = new JFrame("A Window");
    frame.setSize(300, 200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField field1 = new JTextField(10);
    field1.setText("1");

    JTextField field2 = new JTextField(10);
    field2.setText("2");

    JButton button1 = new JButton("Make bigger");
    button1.addActionListener(e -> {
          int val1 = Integer.parseInt(field1.getText());
          int val2 = Integer.parseInt(field2.getText());
          if (val2 > val1)
            field1.setText("" + (val2 + 1));
        });

    JButton button2 = new JButton("Make bigger");
    button2.addActionListener(e -> {
          int val1 = Integer.parseInt(field1.getText());
          int val2 = Integer.parseInt(field2.getText());
          if (val1 > val2)
            field2.setText("" + (val1 + 1));
        });

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 2));  // stay as a 2x2 grid
    panel.add(field1);
    panel.add(button1);
    panel.add(field2);
    panel.add(button2);

    frame.add(panel);
    frame.setVisible(true);
  }
}