
CHAPTER 26
Thejavax.swing.event Package
The javax.swing .event package augments the java.awt.event package and defines event
objects, listeners, and adapters that are specific to Swing components. Classes with
names ending in “Event” define event types; their fields and methods provide
details about the event that occurred. Interfaces with names ending in “Listener”
ar e event listeners. The methods of these interfaces are invoked to notify inter-
ested objects when specific events occur. Classes with names ending in “Adapter”
ar e convenient no-op implementations of listener interfaces. Typically, it is easier
to subclass an adapter class than implement the corresponding listener interface
fr om scratch. Figure 26-1 shows the event classes of this package, while Figure
26-2 shows the event listeners.
AncestorEvent Ja va 1.2
javax.swing .event serializable event
An event of this type is generated by a JComponent when it is moved, becomes visible,
or becomes invisible. Often, the event is generated when one of the component’s
ancestors is moved, becomes visible, or becomes invisible. The inherited getID() method
retur ns the type of the event, which is one of the constants defined by the class. ANCES-
TOR_ADDED is used when the component becomes visible, and ANCESTOR_REMOVED is
used when the component becomes invisible. getAncestor() retur ns the ancestor compo-
nent that was modified, and, as a convenience, ...