The Delegation Event Model

The delegation event model derives its name from the fact that event handling is delegated from an event source to one or more event listeners.

The premise behind the delegation event model is simple: components fire events, which can be listened for and acted upon by listeners. Listeners are registered with a component by invoking one of a number of addXYZListener(XYZListener) methods. After a listener is added to a component, appropriate methods in the listener's interface will be called when the corresponding type of event is fired by the component.

Components, Events and Listeners

The applet listed shown in Figure 9-1 and listed in Example 9-1 illustrates the fundamental concepts of the delegation event model.

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.