Java event-driven and java event-driven

Source: Internet
Author: User

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

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.