- 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.
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