1, the event processing process, mainly involves three kinds of objects:
Event Source: The place where events occur, usually the individual components, such as: Buttons, windows, menus, and so on.
Event: An event encapsulates a specific thing that occurs on a GUI component (usually a single user action). (EventObject)
EventListener (Event Listener): Responsible for listening to events that occur at the source of the event and handling various events accordingly.
2. AWT Event handling mechanism: a delegate-type (delegation) Event processing method.
Steps of the AWT event handling mechanism:
- Implements the event listener class, which is a special Java class that must implement a Xxxlistener interface.
- Creating an event Source
- Call the Addxxxlistener () method to register the event listener object with the normal component (the event source).
3. AWT events fall into two main categories: low-level events and advanced events
1. Low-level events
A low-level event is an event based on a specific action.
- ComponentEvent: A component event that is triggered when the component size changes, the position moves, and the display/hide state changes.
- ContainerEvent: A container event that is triggered when a container has added components and removed components.
- WindowEvent: A window event that is triggered when the window state changes.
- Foucusevent: A focus event that is triggered when the component gets or loses focus.
- KeyEvent: Keyboard event.
- MouseEvent: Mouse event.
- paintevent: Component Draw event. The event is a special event type that fires when the GUI component calls the Update/paint method to render itself, and the event is not dedicated to the event-handling model.
2. Advanced Events
An advanced event is based on a semantic event that can be associated with a specific action and depends on the class that triggered the event.
- ActionEvent: Action event, when a button, menu item is clicked to trigger the event.
- AdjustmentEvent: Adjusts the event.
- ItemEvent: Option event.
- Txtevent: Text event.
4. Event Adapter
The event adapter is an empty implementation of the listener interface and provides an implementation for each method in the interface.
Java Event handling