Research on Event Handling Models of Java

Yue Wu, Jing Wu, Zhou Ming-tian · 中国电子科技:英文版 · 2004

A new event-handling paradigm and its application model are proposed. The working mechanism and principle of event listener model is given in detail. Finally, the launching event mechanisms, the choosing event handling models and the dispatching mechanism are illustrated. A software event indicates some action has occurred, to which a program might respond. Typical events includes keystrokes, mouse movement, button clicks, and messages receipts from the network, etc. Event handling is the ability to send and receive event notifications. Generally, there are four elements concerned in event handling: Event type: abstraction describing a set of related events; Event generator: object that generated the event; Event dispatcher: object that is responsible for dispatching the event to event handlers; Event handler: object that deals with the An event may be generated by program or user action. The event generator, event dispatcher, or/and event handler may be the same object or different objects. The event handler may be one or more objects. The event handling can be specified as when an event generator detects an event, the relevant event dispatcher notifies the related event handlers, then the event handlers respond the event. There are two famous event handling models (1) . One is called inheritance model, which is based on inheritance. Another one is called event listener model, or delegation event model. Inheritance model is used in JDK 1.0. Events are encapsulated in a single class named Event. Only AWT component objects could handle events in the handleEvent() method which is called action() method. For catching and handling events, the component that handles an event has to be either the component in which the event occurred or a component above it in the component containment hierarchy. The handleEvent() method either handles events and returns true, or false or super, handleEvent() to propagate them up the containment hierarchy. So there are two choices for handling an event in the following: Let each subclass of AWT components handling its events by overriding either action() or handleEvent() methods and returning true; Let a particular container handle all events for its subclasses.

Read the paper · More papers on PaperTik