Setting up ActionEvents for a Button
When the button is created, it should have at least one listener class added to its list of listeners:
- button1.addActionListener ( eventclass );
where eventclass is an instance of the listener class.
- every component which can cause an event called X, has methods addXListener and removeXListener.
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) { ... }
- }
If the event source class is acting as its own listener, then you just say
- button1.addActionListener ( this );