The listener in Java refers to the method that listens and is responsible for processing events, also called an event listener. Listening in Java involves three parts: 1. Events; 2. Event listeners; 3. Event sources. An operation performed by a user on a component is called an event.
The listener in Java refers to the method that listens and is responsible for processing events, also called an event listener. Listening in Java involves three parts: 1. Events; 2. Event listeners; 3. Event sources. An operation performed by a user on a component is called an event.
(Video tutorial recommendation: java course)
The execution sequence is as follows:
1. Register a listener for the event source
2. The component accepts external effects, that is, the event is triggered
3. The component generates a corresponding event object and passes this object to the associated event handler
4. The event handler starts and executes relevant code to handle the event.
Listener mode:
After the event source registers the listener, when the event source triggers an event, the listener can call back the method of the event object.
More vividly speaking, The listener mode is based on: registration-callback event/message notification processing mode, which means that the monitored person notifies all monitors of the message.
Related recommendations: java introductory tutorial
The above is the detailed content of What is a listener in java. For more information, please follow other related articles on the PHP Chinese website!