Java Event handling

Source: Internet
Author: User

1, the event processing process, mainly involves three kinds of objects:

Event Source: The place where events occur, usually the individual components, such as: Buttons, windows, menus, and so on.

Event: An event encapsulates a specific thing that occurs on a GUI component (usually a single user action). (EventObject)

EventListener (Event Listener): Responsible for listening to events that occur at the source of the event and handling various events accordingly.

2. AWT Event handling mechanism: a delegate-type (delegation) Event processing method.

Steps of the AWT event handling mechanism:

    • Implements the event listener class, which is a special Java class that must implement a Xxxlistener interface.
    • Creating an event Source
    • Call the Addxxxlistener () method to register the event listener object with the normal component (the event source).

3. AWT events fall into two main categories: low-level events and advanced events

1. Low-level events

A low-level event is an event based on a specific action.

    • ComponentEvent: A component event that is triggered when the component size changes, the position moves, and the display/hide state changes.
    • ContainerEvent: A container event that is triggered when a container has added components and removed components.
    • WindowEvent: A window event that is triggered when the window state changes.
    • Foucusevent: A focus event that is triggered when the component gets or loses focus.
    • KeyEvent: Keyboard event.
    • MouseEvent: Mouse event.
    • paintevent: Component Draw event. The event is a special event type that fires when the GUI component calls the Update/paint method to render itself, and the event is not dedicated to the event-handling model.

2. Advanced Events

An advanced event is based on a semantic event that can be associated with a specific action and depends on the class that triggered the event.

    • ActionEvent: Action event, when a button, menu item is clicked to trigger the event.
    • AdjustmentEvent: Adjusts the event.
    • ItemEvent: Option event.
    • Txtevent: Text event.

4. Event Adapter

The event adapter is an empty implementation of the listener interface and provides an implementation for each method in the interface.

  

Java Event handling

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.