Events
Handle events
Structure event handling
Two steps to handle any event
- Create a class that implements the appropriate listener interface. In this class, you must code an implementation of the appropriate listener interface method to respond to the event.
- Register an instance of the listener class to the event source by calling the appropriate addeventListener method
Four options for implementing the listener interface
- Implement it in the panel itself
- Implement it in a separate class
- Implement it in an inner class within the panel
- Implement it in an anonymous inner class
Two options for handling multiple event sources
- Create one listener that handles all events for the panel
- Create a separate listener for each event