Java Reference
In-Depth Information
AWT
has a set of standard
GUI
components: labels, buttons, check boxes,
choice lists, scroll bars, text fields, text regions, and so on. Several top-
level containers, such as dialog boxes and windows, let you place other
components inside them (preferably using a relative-placement layout
manager).
When you need to draw your own graphics on the screen, the simplest
technique is to subclass
Component
or
Container
, overriding the
paint
method to draw what you need using the
Graphics
object passed to
paint
.
Component
is the basis for many customized user-interface com-
ponents when no standard component does what is needed. You would
subclass
Container
if your drawn component contained other compon-
ents.
The
AWT
is an event-based system. When the user performs an action,
such as moving a mouse, clicking a mouse button, or typing a key,
an event is generated that identifies the underlying component as the
source of that event and that encapsulates the nature of that event. The
event is then placed in a central
event queue,
and will be serviced by
a single
event thread.
The event thread takes events from the queue
one at a time and dispatches them to their source components. You can
also generate events programmaticallyfor example, invoking
repaint
on
a component puts an
UPDATE
event into the event queueor can create
event objects and insert them directly into the event queue.
Components are notified of events (mouse up, mouse down, mouse
drag, keyboard events, and the like) by having methods invoked on
them by the event thread. You can also register
listener
objects that are
notified when an event occurs within a component. For example, a but-
ton that lets the user exit the program might be set up like this:
Button b = new Button("Exit");
b.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}