Java Reference
In-Depth Information
extends
MenuItem
to create arbitrarily complex menus.)
Menu
is subclassed
by
PopupMenu
to describe a menu that can be dynamically popped up at a
specified position within a component.
Component
declares many nonmenu component-oriented methods. For example,
Component
declaresthefollowingmethodstoinformthecalleraboutthecomponent's
displayable, visible, and showing status:
•
boolean isDisplayable()
returnstruewhenacomponentisinthe
dis-
playable state
(thecomponentisconnectedtoanativescreenresource[defined
shortly], typically by being added to a container).
•
boolean isVisible()
returns true when a component is in the
visible
state
(thecomponentappearsonthescreen).Thecompanion
void setVis-
ible(boolean b)
methodletsyoushow(
b
is
true
)orhide(
b
is
false
)
a component.
•
boolean isShowing()
returns true when a component is in the
showing
state
(thecomponentisvisibleandiscontainedinacontainerthatisalsovisible
andshowing).Thismethodisusefulfordeterminingwhetherornotacompon-
ent has been obscured by another component. It returns false when obscured,
whereas
isVisible()
would continue to return true.
MenuComponent
'srepertoireofmethodsismuchshorter.However,itsharessome
commonality with
Component
. For example, both classes declare a method for spe-
cifying the component's font.
Some of
Component
's and
MenuComponent
's methods have been deprecated
and should not be used. For example,
Component
declares
java.awt.peer.ComponentPeer getPeer()
and
MenuComponent
de-
clares
java.awt.peer.MenuComponentPeer getPeer()
. Both deprecated
methods hint at how AWT implements its predefined components.
AWT leverages the platform's windowing system to create various components.
Whenyouaddacomponenttoacontainer,AWTcreatesapeerobjectwhoseclassim-
plementsa
ComponentPeer
or
MenuComponentPeer
subinterface.Forexample,
AWT creates a
java.awt.peer.ButtonPeer
instance when you add a
Button
component class instance to a container.
Note
Each AWT toolkit implementation includes its own set of peer interface im-
plementations.
Behind the scenes, the component object communicates with the peer object, which
communicateswithnativecodeinaJDKlibrary.Thiscodecommunicateswiththeplat-