Events
Handle events
Java event model
What happens when a button is pressed
What happens when any event occurs
The Java event model
- GUI applications depend on events that represent user interactions such as clicking a button or selecting an item from a list.
- All events are represented by an event object that derives from the EventObject class. The event object contains information about the event that occurred.
- An event listener is an object that responds to an event.
- The class that defines an event listener must implement an event listener interface.
- A component that generates an event is called an event source.
- To respond to an event, an application must register an event listener object with the event source that generates the event.
- The class for the event source provides a method for registering event listeners. Then, when the event occurs, the event source creates an event object and passes it to the event listener.