Java graphical interface event handling mechanism

Source: Internet
Author: User

The Java language provides a series of user graphical interface components, mainly two packages: java.awt, and javax.swing.


Among them, the AWT package is an early package, and the swing package is a late-served user Interface Pack.

The difference between swing package components and AWT package components is that swing package components are generally not dependent on the current platform GUI functionality.

Swing Component Advantages: 1, cross-platform, 2, strong portability, 3, swing expansion of the AWT package, components more rich, more convenient to use.


Event handling mechanism:


The delegate event model is used in Java to handle events.

The delegate event model is divided into three parts: an event source, an event object, and an event listener.


Event Source: An object that can produce an event. such as Windows, text boxes, buttons, drop-down lists, mouse clicks.

Event object: The event object encapsulates information about the event. The event class is predetermined by the system beforehand. Including: ActionEvent, ItemEvent, MouseEvent, KeyEvent, FocusEvent and WindowEvent.

Event Listener: An event listener is also an object. It accepts messages sent from the event source and responds to the event. The object of a class that implements a listener interface can be an event listener. The usual event listener interface is the same as the event object:

ActionListener, ItemListener, MouseListener, KeyListener, Focuslistener and WindowListener.


Event Processing Flow:

The event object registers the event listener, which triggers the event listener to handle the event when the event source occurs.

In a nutshell: Sign-up and listen-and process

This article is from the "pin-soil" blog, please be sure to keep this source http://3240611.blog.51cto.com/3230611/1553024

Java graphical interface event handling mechanism

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.