The blanks are filled in below:
public class ButtonDemo2 extends JFrame implements ActionListener { JButton bChange; public buttonDemo2() { getContentPane().setLayout( new FlowLayout() ); bChange = new JButton("Click Me!"); getContentPane().add( bChange ); } public void actionPerformed( ActionEvent evt) { . . . . . . } public static void main ( String[] args ) { ButtonDemo2 frm = new ButtonDemo2(); . . . . . } }
In this style of GUI programming,
one object (the ButtonDemo2
object) is playing several roles:
it is the container object, and it is also the listener object.
However, implementing ActionListener
is not enough.
The listener must still be registered with the Button.