A detailed explanation of event handling mechanism in Java GUI programming

Source: Internet
Author: User

1 Event: User to a certain functional operation of the program.

There are two main types of events in Java:

1. Component Class Events

ComponentEvent, ContainerEvent, WindowEvent, FocusEvent, PaintEvent, MouseEvent a total of six major categories,

They all occur when the state of the component changes.

2. Action class Events

ActionEvent, TextEvent, AdjustmentEvent, itemevent a total of four categories.

They all correspond to a certain functional action of the user.

The event classes in Java are included in the JDK's Java.awt.event package.

2 Event Programming:

User programming defines how the program should respond when each particular event occurs, and the response code is automatically invoked by the system when the corresponding event occurs.

3 Event Delegate Authorization processing model

JDK1.1 the above version realizes the mechanism of the event delegate authorization processing model.

① Event Source: The component of the output event.

② Listener: The generation that responds specifically to the events generated by the component, that is, the event output and processing are programmed by two different classes, which can be placed in separate programs respectively.

③ event handling mechanism: The AWT component itself does not programmatically handle the corresponding event, which is referred to the event listener (it can be the container class of the component or the other Java program class, as long as they implement the relevant event listener interface) (the event authorization processing model).

④ Event-Handling Package: Java.awt.event package, which provides the classes and interfaces required by the AWT event

The ActionEvent class corresponds to the ActionListener interface;

The MouseEvent class corresponds to the Mousemotionlistener interface and the MouseListener interface;

The Windonevent class corresponds to the Windonlistener interface---The Xxxevent type event occurs, the interface that handles the event is Xxxlistener), and their parent class is the EventObject class.

Description of individual event classes:

EventObject: Super class for all event classes

The most important method-GetSource (), returns the object that generated the event

AWTEvent: Super class for all AWT event classes

The most important method-GetID (), returns the ID number of an event whose ID is an integer that specifies the type of event, such as a button event or a mouse click event

ActionEvent: Events that occur when the component is activated

AdjustmentEvent: Events that occur when adjusting an adjustable component, such as moving a scroll bar

ComponentEvent: A high-level event that occurs when a component is manipulated

ContainerEvent: Occurs when a component is added or removed to a container

InputEvent: A high-level event generated by an input device

ItemEvent: Occurs when selecting from a Select item, check box, or list

KeyEvent: Occurs when manipulating the keyboard

MouseEvent: Occurs when manipulating the mouse

PaintEvent: An event that occurs when a component is depicted

TextEvent: Occurs when text is changed

WindowEvent: An event that occurs when the window is manipulated, such as maximizing or minimizing a window.

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.