Java Reference
In-Depth Information
Classes in the java.awt
package except that
Applet is in the
java.applet package
Dimension
LayoutManager
1
Heavyweight
Font
FontMetrics
Object
Color
Panel
Applet
JApplet
Graphics
Component
Container
Window
Frame
JFrame
*
Dialog
JDialog
Swing GUI
components such as
JButton, JLabel,
JTextField, JPanel,
etc.
JComponent
Swing Components
in the javax.swing
package
Lightweight
F IGURE 12.1
Java GUI programming utilizes the classes shown in this hierarchical diagram.
Note
The JFrame , JApplet , JDialog , and JComponent classes and their subclasses are
grouped in the javax.swing package. Applet is in the java.applet class. All the
other classes in Figure 12.1 are grouped in the java.awt package.
12.3.1 Component Classes
An instance of Component can be displayed on the screen. Component is the root class of all
the user-interface classes including container classes, and JComponent is the root class of all
the lightweight Swing components. Both Component and JComponent are abstract classes
(abstract classes will be introduced in Chapter 15). For now, all you need to know is that
abstract classes are the same as classes except that you cannot create instances using the new
operator. For example, you cannot use new JComponent() to create an instance of
JComponent . However, you can use the constructors of concrete subclasses of JComponent
to create JComponent instances. It is important to become familiar with the class inheritance
hierarchy. For example, the following statements all display true:
abstract class
JButton jbtOK = new JButton( "OK" );
System.out.println(jbtOK instanceof JButton);
System.out.println(jbtOK instanceof JComponent);
System.out.println(jbtOK instanceof Container);
System.out.println(jbtOK instanceof Component);
System.out.println(jbtOK instanceof Object);
12.3.2 Container Classes
An instance of Container can hold instances of Component . A container is called a top-
level container if it can be displayed without being embedded in another container. Window ,
Frame , Dialog , JFrame , and JDialog are top-level containers. Window , Panel , Applet ,
Frame , and Dialog are the container classes for AWT components. To work with Swing
components, use Container , JFrame , JDialog , JApplet , and JPanel , as described in
Table 12.1.
top-level container
 
 
Search WWH ::




Custom Search