During the course of this chapter, we’ve built up our own message-handling framework from scratch, relying on basic sockets, I/O streams, and object serialization to implement a protocol for sending, receiving, and handling messages. In this section, we’ll look at merging a message-passing framework with the Java event model that’s used in the AWT package for handling GUI events. The advantage of using events is the possibility of integrating your distributed system with other systems based on the Java event model, including AWT-based applications or applets.
The event model included in the Java
API (version 1.1 and later) is generic enough to build event-handling
protocols for general applications, not just GUI-related ones. The
Java event model is based on
are created by various event sources and handled by classes that
Different types of events are defined by creating subclasses of the
EventObject class. The
class only contains a source
Object. Subclasses of
EventObject can add additional data to represent
event specifics. For example, the AWT package defines a
KeyEvent subclass that represents keyboard
KeyEvent class contains data fields
that specify which key was pressed to generate the event.
The Java event model is called a
model; events are generated by a
source of some kind, and
EventListeners register themselves with the event ...