Java Reference
In-Depth Information
Button btnYes = new Button("Yes");
Note
Iliketoprefixacomponentvariabletoindicateitskind.Forexample,Iprefix
buttons with
btn
.
Containers Overview
Buttons,labels,textfields,andothercomponentscannotbeplaceddirectlyonthescreen;
they need to be placed in a container window that is placed directly on the screen.
presents their hierarchy.
Figure 7-3.
AWT's container class hierarchy is rooted in
Container
.
AWT's
Container
classistherootclassforallAWTcontainers.Directlybeneath
Container
are
Panel
,
ScrollPane
, and
Window
:
•
Panel
isthesimplestcontainer.Itprovidesspaceinwhichanapplicationcan
attach any other component, including other panels.
•
ScrollPane
implements automatic horizontal and/orvertical scrolling fora
single
child
(contained) component. A container that contains a component is
referred to as that component's
parent
.
•
Window
isatop-levelwindowwithnoborders.Its
Dialog
subclassdescribes
a
dialog box
(awindowforsolicitinginputfromtheuser)andits
Frame
sub-
class describes a
frame window
(a top-level window with borders, including a
titlebar).
Dialog
's
FileDialog
subclass describes a dialog box for select-
ing a file.
Container
declaresmanycontainer-orientedmethods.Forexample,
Component
add(Component comp)
appends component
comp
to the container,
Compon-