Yes. The system does not know which
events will be ignored, so it
creates an Event
object for each one.
import java.awt.*; import java.awt.event.*; import javax.swing.*; class ButtonFrame2 extends JFrame implements ActionListener { JButton bChange; ButtonFrame2() { . . . . . . } // listener method for the ActionListener interface public void actionPerformed( ActionEvent evt) { . . . . . . } }
A button listener must
implement the ActionListener
interface.
ActionListener
is an interface (not a class)
that contains a
single method:
public void actionPerformed( ActionEvent evt) ;
A class that implements the interface must contain an
actionPerformed()
method.
The ActionEvent
parameter
is an Event
object that represents an event (a button click).
It contains information about the event.
Import the package java.awt.event.*
if you are dealing with events.
The listener object could be defined in a class other than the frame class. In our example, the class that holds the component is also the listener for its events.
Our revised class ButtonFrame2
says that it
implements ActionListener
.
What does this mean?