The blanks are filled in below:
class ButtonFrame extends JFrame implements ActionListener { JButton bChange ; // constructor public ButtonFrame() { bChange = new JButton("Click Me!"); getContentPane().setLayout( new FlowLayout() ); getContentPane().add( bChange ); setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ); } // listener method required by the interface public void actionPerformed( ActionEvent evt) { . . . . . . } }
In this style of GUI programming,
one object (the ButtonFrame
object) is playing two roles:
it is the container object that holds a GUI component,
and it is also the listener object for that component.
Implementing ActionListener
is not enough.
The listener must still be registered with the JButton
.
(Review: ) What does registering a listener do?