import javax.swing.JButton; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /* Author: James Tam Version: 2015 Learning objective: defining an innner class to handle GUI events (in this case a window event). */ public class Driver { public static final int WIDTH = 300; public static final int HEIGHT = 200; public static void main (String [] args) { MyFrame aFrame = new MyFrame (); aFrame.setSize (WIDTH,HEIGHT); JButton aButton = new JButton("Press me."); // Anonymous object/class aButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton aButton = (JButton) e.getSource(); aButton.setText("Stop pressing me!"); } }); aFrame.add(aButton); aFrame.setVisible(true); } }