import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Square extends JFrame { private class Controller implements ActionListener { public void actionPerformed(ActionEvent e) { int value; value= Integer.parseInt(input.getText()); input.setText(Integer.toString(value * value)); } } private JButton button; private JTextField input; public Square() { super("Square GUI"); button = new JButton("Square"); input = new JTextField(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new GridLayout(1,2)); add(button); add(input); button.addActionListener(new Controller()); pack(); setVisible(true); } public static void main(String[] args) { Square app; app = new Square(); } }