img
The eventMask argument is a bit mask that defines the events to be delivered to this component.
The AWTEvent class defines int constants for making this mask. Several are shown here:
ACTION_EVENT_MASK
KEY_EVENT_MASK
ADJUSTMENT_EVENT_MASK
MOUSE_EVENT_MASK
COMPONENT_EVENT_MASK
MOUSE_MOTION_EVENT_MASK
CONTAINER_EVENT_MASK
MOUSE_WHEEL_EVENT_MASK
FOCUS_EVENT_MASK
TEXT_EVENT_MASK
INPUT_METHOD_EVENT_MASK
WINDOW_EVENT_MASK
ITEM_EVENT_MASK
You must also override the appropriate method from one of your superclasses in order
to process the event. Table 24-2 lists the methods most commonly used and the classes that
provide them.
The following sections provide simple programs that show how to extend several AWT
components.
Extending Button
The following program creates an applet that displays a button labeled "Test Button". When
the button is pressed, the string "action event: " is displayed on the status line of the applet
viewer or browser, followed by a count of the number of button presses.
The program has one top-level class named ButtonDemo2 that extends Applet. A static
integer variable named i is defined and initialized to zero. This records the number of button
pushes. The init( ) method instantiates MyButton and adds it to the applet.
Class
Processing Methods
Button
processActionEvent( )
Checkbox
processItemEvent( )
CheckboxMenuItem
processItemEvent( )
Choice
processItemEvent( )
Component
processComponentEvent( ), processFocusEvent( ),
processKeyEvent( ), processMouseEvent( ),
processMouseMotionEvent( ),
processMouseWheelEvent( )
List
processActionEvent( ), processItemEvent( )
MenuItem
processActionEvent( )
Scrollbar
processAdjustmentEvent( )
TextComponent
processTextEvent( )
TABLE 24-2
Commonly Used Event Processing Methods
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home