Java event-driven and java event-driven
In java, events are not handled by the event source, but are handled by the event listener. The event source (such as a button) must be separated from the specific processing of the event. This is the so-called event Delegate processing model.
The event Delegate processing model consists of the event source that generates the event, the event object that encapsulates the Event-related information, and the event listener. For example, when a button is clicked by the mouse, an "ActionEvent" is triggered, and the Java system generates an "event object" to indicate this event, the event object is then passed to the "event listener", and the event listener specifies the relevant interface method for processing. To enable the event listener to receive the event object information, the event listener must register with the event source in advance.
Class A is responsible for creating the listener, then A must first XXXListener interface, that is, the class that implements the XXXlistener interface can instance A listener.
1 class A implements XXXListener {2 interface method ..... 3}
1 event source. addXXXListener (event listener)
Implementation Method
1. Internal class
2. Anonymous internal class
3. Perform interface implementation, event response, and listener registration in a class.
Some interfaces of the simplified tool define many methods, but we only need some of them, so we need to use the Object Adapter class. The adapter class inherits the corresponding interface and implements all the methods (empty methods). We only need to inherit the adapter class and implement the methods we need. It is commonly implemented using the internal class inheritance adapter.
Events triggered by components and event handling methods
Common java event classes