1 |
When the button is created, it should have at least one listener class added to its list of listeners:
-
button1.addActionListener ( eventclass );
|
2 |
where eventclass is an instance of the listener class.
-
every component which can cause an event called X, has methods addXListener and removeXListener.
|
3 |
Then this class must implement the interface ActionListener. This interface requires only one event handler method:
-
public class EventClass implements ActionListener
-
{
-
public void actionPerformed ( ActionEvent e) { ... }
-
}
|
4 |
If the event source class is acting as its own listener, then you just say
-
button1.addActionListener ( this );
|