import javax.swing.*; import java.awt.event.*; class Ten extends JFrame implements KeyListener, ActionListener { JButton submitButton = new JButton("Click me!"); JLabel nameLabel = new JLabel("Name: "); JTextField nameField = new JTextField(10); Ten(String title, int width, int height) { JPanel panel = new JPanel(); panel.add(nameLabel); panel.add(nameField); panel.add(submitButton); this.add(panel); this.submitButton.addActionListener( this ); this.nameField.addKeyListener( this ); this.setSize(width, height); this.setTitle(title); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String[] args) { Ten f = new Ten("Simple Frame", 300, 100); } public void keyPressed (KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyTyped (KeyEvent e) { System.out.println( e.getKeyChar() ); } public void actionPerformed(ActionEvent e) { System.out.println( this.nameField.getText() ); this.nameField.setText( "" ); } }