201671010130 2016-2017-2 "Java Programming" 13th Week study Summary

Source: Internet
Author: User
Tags event listener set background

    • Fundamentals of event handling : The event source (the object that registers the listener and sends the event object to the listener), the event listener (which receives the event source and responds), the event object (encapsulating event-related information).

    • Event-generated events are set as parameters, received by the listener method, and the specific event is handled by the corresponding method. For example 11-1 Click button(yellow), there is a corresponding action set background color of Yellow . (This procedure invokes the actionperformed method implementation in listener Coloraction).

    • To respond to and process an event, you must complete two steps: Registering an event listener that implements the specified interface, defining an event listener class that implements an event listener interface, and materializing an event-handling abstract method declared in the interface.

    • adapters can be used instead of interfaces to handle events , when when Java provides more than one method for handling events,Java provides an adapter class, such as the windowadapter class, accordingly. The adapter has implemented the appropriate interface, such as the windowadapter class implements the windowlistener interface. Therefore, you can use objects created by the Windowadapter subclass to do the monitor, overriding the required interface methods in the subclass.

    • Mouse Events MouseEvent

Event Source: Mouse events can occur on any component

Mouse events are triggered when the mouse enters the component, exits the component, clicks the mouse over the component, drags the mouse, and so on.

Registration Monitor:

Addmouselistener (MouseListener Listener)

Addmousemotionlistener (Mousemotionlistener Listener)

Event Handling: The MouseListener interface can handle mouse events triggered by the following 5 actions

Press the mouse button on the event source mousepressed (MouseEvent)

Release the mouse button on the event source mousereleased (MouseEvent)

Click the mouse button on the event source mouseclicked (MouseEvent)

mouse into Event source mouseentered (MouseEvent)

Mouse Exit Event source mouseexited (MouseEvent)

201671010130 2016-2017-2 Java programming 13th Week of study summary

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.