Java Reference
In-Depth Information
Each of these event classes defines methods that enable you to analyze an event. For a MouseEvent ob-
ject, for example, you can get the coordinates of the cursor when the event occurred. These low-level event
classes also inherit methods from their superclasses and are related in the manner shown in Figure 18-3 .
FIGURE 18-3
AWTEvent is derived from java.util.EventObject . The EventObject class implements the Seri-
alizable interface, so all objects of the event classes in the diagram are serializable. It also defines a
getSource() method that returns the source of an event as type Object . All the event classes shown inherit
this method.
The AWTEvent class defines constants that are public final values identifying the various kinds of events.
These constants are named for the sake of consistency as the event name in capital letters, followed by
_ MASK . The constants identifying the low-level events that you are most likely to be interested in are the fol-
lowing:
MOUSE_EVENT_MASK MOUSE_MOTION_EVENT_MASK
MOUSE_WHEEL_EVENT_MASK KEY_EVENT_MASK
ADJUSTMENT_EVENT_MASK WINDOW_EVENT_MASK
WINDOW_FOCUS_EVENT_MASK WINDOW_STATUS_EVENT_MASK
TEXT_EVENT_MASK ITEM_EVENT_MASK
FOCUS_EVENT_MASK
Each constant is a value of type long with a single bit set to 1. Because they are defined this way you can
combine them using a bitwise OR operator and you can separate a particular constant out from a combina-
tion by using a bitwise AND.
WARNING Theprovidedlistofeventmasksisnotexhaustive.Therearemasksforcomponent
events represented by objects of the class ComponentEvent and for container events. These
events occur when a component is moved or resized, or a component is added to a container,
for example. There is also a mask for events associated with components that receive text in-
put. You won ' t normally need to get involved in these events so I don ' t discuss them further.
 
 
Search WWH ::




Custom Search