
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
NightSky: A Delegation Event Model Example
|
433
The Event Listener Class
Our night sky application’s event listener class is NightSky. It implements the
RandomizerListener interface and defines an onRandomAction( ) method. When
NightSky is constructed, it creates a sky background. Each time Randomizer invokes
onRandomAction( ) on NightSky, the NightSky class creates a shooting star anima-
tion over the sky background.
The Overall Structure
Figure 19-2 shows the structure of the night sky application. Compare Figure 19-2
with the generic delegation event model structure shown earlier in Figure 19-1. Spe-
cifically, Randomizer is our EventSourceClass, RandomizerListener is our
EventTypeListener, RandomizerEvent is our EventTypeEvent, and NightSky is our
EventListenerClass. The parameter,
l, passed to addRandomizerListener( ) and
removeRandomizerListener( ) in Figure 19-2 is the listener to be added or removed.
Now let’s take a closer look at the code in the night sky application.
Randomizer, RandomizerListener, and RandomizerEvent
The Randomizer and RandomizerEvent classes and the RandomizerListener interface
work together to provide event-broadcast services for the Randomizer class. Concep-
tually, every delegation event model implementation will have the same three partici-
pants—a class ...