Container getContainer( )
ThegetChild( )method returns a reference to the component that was added to or removed
from the container. Its general form is shown here:
Component getChild( )
The FocusEvent Class
AFocusEventis generated when a component gains or loses input focus. These events are
identified by the integer constantsFOCUS_GAINEDandFOCUS_LOST.
FocusEventis a subclass ofComponentEventand has these constructors:
FocusEvent(Componentsrc, inttype)
FocusEvent(Componentsrc, inttype, booleantemporaryFlag)
FocusEvent(Componentsrc, inttype, booleantemporaryFlag, Componentother)
Here,srcis a reference to the component that generated this event. The type of the event is
specified bytype.The argumenttemporaryFlagis set totrueif the focus event is temporary.
Otherwise, it is set tofalse. (A temporary focus event occurs as a result of another user
interface operation. For example, assume that the focus is in a text field. If the user moves
the mouse to adjust a scroll bar, the focus is temporarily lost.)
The other component involved in the focus change, called theopposite component,is passed
inother.Therefore, if aFOCUS_GAINEDevent occurred,otherwill refer to the component that
lost focus. Conversely, if aFOCUS_LOSTevent occurred,otherwill refer to the component
that gains focus.
You can determine the other component by callinggetOppositeComponent( ),
shown here:
Component getOppositeComponent( )
The opposite component is returned.
TheisTemporary( )method indicates if this focus change is temporary. Its form
is shown here:
boolean isTemporary( )
The method returnstrueif the change is temporary. Otherwise, it returnsfalse.
The InputEvent Class
The abstract classInputEventis a subclass ofComponentEventand is the superclass for
component input events. Its subclasses areKeyEventandMouseEvent.
InputEventdefines several integer constants that represent any modifiers, such as the
control key being pressed, that might be associated with the event. Originally, theInputEvent
class defined the following eight values to represent the modifiers:
ALT_MASK BUTTON2_MASK META_MASK
ALT_GRAPH_MASK BUTTON3_MASK SHIFT_MASK
BUTTON1_MASK CTRL_MASK
Chapter 22: Event Handling 643