Java Reference
In-Depth Information
Swing is built on top of the AWT, and as a result, the event-handling
model is unchanged. Programming in Swing is very similar to the program-
ming in Java 1.1 AWT, except that many names have changed. In this appen-
dix we describe Swing programming only. Swing is a large library; it is not
unusual to see entire books devoted to the topic, so our presentation greatly
understates the issues that are involved in user interface design.
Figure B.1 illustrates some of the basic components provided by Swing.
These include the JComboBox (currently Circle is selected), a JList (currently blue
is selected), basic JTextField s for input, three JRadioButton s and a JCheckBox ,
and a JButton (named Draw ). Next to the button is a JTextField that is used for
output only (hence, it is darker than the input JTextField s above it). In the top
left-hand corner is a JPanel object that can be used for drawing pictures and
handling mouse input.
This appendix describes the basic organization of the Swing API. It
covers the different types of objects, how they can be used to perform
input and output, how these objects are arranged in a window, and how
events are handled.
basic objects in swing
B.2
The AWT and Swing are organized using a class inheritance hierarchy. A
compressed version of this hierarchy is shown in Figure B.2. This is com-
pressed because some intermediate classes are not shown. In the full hierar-
chy, JTextField and JTextArea , for instance, are extended from JTextComponent ,
while many classes that deal with fonts, colors, and other objects and are not
in the Component hierarchy are not shown at all. The classes Font and Color ,
which are defined in the java.awt package, are extended from Object .
figure B.1
A GUI that illustrates some of the basic Swing components
 
 
Search WWH ::




Custom Search