Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

TheeventMaskargument is a bit mask that defines the events to be delivered to this component.
TheAWTEventclass definesintconstants 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 namedButtonDemo2that extendsApplet. A static
integer variable namediis defined and initialized to zero. This records the number of button
pushes. Theinit( )method instantiatesMyButtonand adds it to the applet.


Chapter 24: Using AWT Controls, Layout Managers, and Menus 749


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

Free download pdf