Applets and the Java 1.0 Event Model
The AWT event model changed dramatically between Java 1.0 and 1.1. Chapter 11 described the Java 1.1 event-handling model exclusively, since the Java 1.0 event model is now deprecated. However, because there is still a (dwindling) installed base of web browsers that support only the Java 1.0 event model, applets are sometimes still written using this model. This section briefly describes Java 1.0 event handling and includes an example applet that uses the model.[1]
In Java 1.0, all events are represented by the java.awt.Event
class. This class has a
number of instance fields that describe the event. One of these
fields, id
, specifies the type of
the event. Event
defines a number
of constants that are the possible values for the id
field. The target
field specifies the object (typically
a Component
) that generated the
event, or on which the event occurred (i.e., the source of the event).
The other fields may or may not be used, depending on the type of the
event. For example, the x
and
y
fields are defined when id
is BUTTON_EVENT
, but not when it is ACTION_EVENT
. The arg
field can provide additional
type-dependent data.
Java 1.0 events are dispatched first to the handleEvent( )
method of the Component
on which they occurred. The
default implementation of this method checks the id
field of the Event
object and dispatches the most
commonly used types of events to various type-specific methods, listed
in Table 16-1.
Table 16-1. Java 1.0 event-processing ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.