A good answer might be:

To a listener object. But our program does not have one, yet.

ActionListener

An ActionListener is a listener for button clicks. ActionListener is an interface (not a class) that contains the single method:

public void actionPerformed( ActionEvent evt) ;
The ActionEvent parameter it expects is an object that represents an event (for us, a button click.) It contains information that can be used in responding to the event. Since ActionListener is an interface, you use it with a class that will implement the actionPerformed() method. It is common to implement the interface in the same class that contains the button(s):

public class buttonDemo extends Frame implements ActionListener
{
  Button bChange = new Button("Click Me!"); // construct a Button

  buttonDemo()                     // constructor for buttonDemo
  {
    setLayout( new FlowLayout() ); // choose the layout manager 
    add( bChange );                // add the button to the container
  }
  
  public void actionPerformed( ActionEvent evt)
  {
     . . . . . .
  }

  public static void main ( String[] args )
  {
    buttonDemo frm = new buttonDemo();
      . . . . .
  }
}

This is a slightly different approach than was used with the WindowEvent of the previous chapter, where the WindowAdapter class was extended to define a spearate class for the listener.

QUESTION 5:

Our class definition buttonDemo says that it implements the ActionListener interface. What does this mean?

Click Here after you have answered the question