Java Reference
In-Depth Information
This appendix examined the basics of the Swing package, which allows the
programming of GUIs. This makes the program look much more professional
than simple terminal I/O.
GUI applications differ from terminal I/O applications in that they are
event-driven. To design a GUI, we write a class. We must decide on the basic
input elements and output elements, pick a layout and issue a
setLayout
com-
mand, add components to the GUI using
add
, and handle events. All this is
part of the class. Starting with Java 1.1, event-handling is done with event lis-
teners.
Once this class is written, an application defines a class that extends
JFrame
with a
main
routine and an event handler. The event handler processes
the window-closing event. The simplest way to do this is to use the
CloseableFrame
class in Figure B.14. The
main
routine simply creates an
instance of this extended frame class, places an instance of the class (whose
constructor likely creates a GUI panel) inside the frame's content pane, and
issues a
pack
command and a
show
command for the frame.
Only the basics of Swing have been discussed here. Swing is the topic of
entire books.
Abstract Window Toolkit (AWT)
A GUI toolkit that is supplied with all Java
systems. Provides the basic classes to allow user interfaces. (930)
ActionEvent
An event generated when a user presses a
JButton
, hits
Return
in a
JTextField
, or selects from a
JList
or
JMenuItem
. Should be handled by the
actionPerformed
method in a class that implements the
ActionListener
interface. (947)
ActionListener
interface
An interface used to handle action events. Contains
the abstract method
actionPerformed
. (947)
actionPerformed
A method used to handle action events. (947)
AWTEvent
An object that stores information about an event. (947)
BorderLayout
The default for objects in the
Window
hierarchy. Used to lay out a
container by placing components in one of five locations (
"North"
,
"South"
,
"East"
,
"West"
,
"Center"
). (941)
ButtonGroup
An object used to group a collection of button objects and guaran-
tee that only one may be
on
at any time. (939)
Search WWH ::
Custom Search