In the GUI, we see how to organize a graphical interface with a graphics tree. However, such a graphical interface is static. We cannot interact with the interface to operate on it. Graphical elements of the GUI need to increase the incident response (event handling) in order to get a dynamic graphical interface.
Elements, events, listeners
We refer to a number of graphical elements in the GUI article. Some events may occur on these graphical elements, such as:
Click on the button
Drag scroll bar
Select Menu
Events in Java Use object representations, such as ActionEvent. Each event has a function of drawing objects, such as buttons, scroll bars, and menus.
The so-called interactive GUI, refers to when the above event occurs, there will be corresponding action generated, such as:
Change color
Change the contents of a window
pop-up menu
Each action is for an event. We put the action in a listener (ActionListener), and then let the listener monitor the event for (a drawing object). When an event occurs, the action in the listener occurs.
Therefore, a responsive GUI is the result of interaction between a graphical object, an event object, and a listener object. We already know how to create a drawing object. We need to add a listener to the drawing object and let the listener catch the event.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/