Java Reference
In-Depth Information
For example, you might want your application to sound one or more beeps when a
long-runningtaskfinishes,toalerttheuserwhomightnotbelookingatthescreen.You
can accomplish this task by specifying code that's similar to the following:
Toolkit toolkit = Toolkit.getDefaultToolkit();
for (int i = 0 ; i < 5; i++)
{
toolkit.beep();
try { Thread.sleep(200); } catch (InterruptedException
ie) {}
}
Thisexamplerevealsthatyoumustobtaina
Toolkit
instancebeforeyoucancall
a
Toolkit
method, and that you do so by calling
Toolkit
's
Toolkit getDe-
faultToolkit()
classmethod.Italsorevealsthatyoumightwanttoplaceasmall
delay between successive beeps to ensure that each beep is distinct.
Components, Containers, Layout Managers, and Events
AWTletsyoucreateGUIsthatarebasedoncomponents,containers,layoutmanagers,
and events.
A
component
is a graphical widget that appears in a window on the screen; a label,
abutton,oratextfieldisanexample.Awindowisrepresentedbyaspecialcomponent
known as a
container
.
A
layout manager
isanobjectthatorganizescomponentsandcontainerswithinacon-
tainer.ItisusedtocreateusefulGUIs(e.g.,aformconsistingoflabels,textfields,and
buttons).
An
event
isanobjectdescribingabuttonclickorotherGUIinteraction.Applications
register
event listener
objects with components to listen for specific events so that ap-
plication code can respond to them.
Components Overview
7-1
presents the class hierarchy for AWT's nonmenu component classes.