Application of the previous two sections of the last section of the content, you can complete a simple interface, but no function, the interface is completely static, if you want to achieve specific functions, you must learn the event model.
Introduction to Event models and common event models
Event control is very important for programs that use a graphical user interface.
A source (event source) generates an event and sends it (the event object) to one or more listeners, and the listener simply waits until it receives an event that the listener will handle once the event is received.
An event source must register the listener so that the listener can receive notifications about a particular event.
Each type of event has its own method of registration, and the general form is:
void Addtypelistener (Typelistener e);
Attention:
The method name of the registered event is not really addtypelistener, where type is the event types, depending on the event, append different types of monitoring, such as: Append button press event to add the Listener method is: addActionListener (ActionEvent e), And E is a reference to an event listener.
The process of event control
The event control process can be divided into the following four steps:
1. The Listener object belongs to an instance of a class that implements a special interface called Listener Interface (Listener interface).
2. The event source is an object that can register one or more listener objects to send the event object to.
3. The event source sends an event object to all registered listeners when an event occurs.
4. The Listener object determines how to respond to this event based on the information encapsulated in the event object.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9E/9A/wKioL1mT6YPh-C-gAAE6NW3ZcAc101.png "title=" Figure 1.png "alt=" Wkiol1mt6yph-c-gaae6nw3zcac101.png "/>
If this process is more abstract, then let's look at a scenario where, in order to monitor traffic violations at the crossroads of the city, a surveillance camera (listener object) is installed at the intersection (event source), which automatically captures violations when a violation occurs (event triggers). And then communicated to the Monitoring Hall, the monitoring hall according to the violation of the situation to make appropriate treatment (incident response, also can be said to be event processing, that is, what to do after the event).
Then it is not difficult to discover the fact that different events need to be captured with different event classes. As shown in 1, the architecture of the common event class.
Let's take a look at the specific description of the event type, as shown in table 1.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/9A/wKioL1mT6ZyRUU7GAAE2ALPefOM508.png "title=" Figure 2.png "alt=" Wkiol1mt6zyruu7gaae2alpefom508.png "/>
We'll cover several common types of events in detail in the next section.
"Full stack Java notes" is a can help you from Zeto long for the full stack of Java Engineer Series of notes. The author is called Mr. G,10 years Java research and development experience, has been in the digital, Aerospace Institute of a Research and development center engaged in software design and research and development work, from small white gradually achieve engineers, senior engineers, architects. Proficient in Java Platform Software development, Master Java EE, familiar with various popular development framework.
The notes contain six parts from shallow into deep:
A-java Introductory Phase
B-Database from beginner to proficient
C-hand Edge mobile front end and web front end
D-j2ee from understanding to combat
E-java Advanced Frame Fine Solution
F-linux and Hadoop
This article is from the "full stack Java Notes" blog, be sure to keep this source http://javanew.blog.51cto.com/12931675/1956779
15.1-Full Stack Java Note: What is the Java event model? What are the steps in the event control process?