Java Reference
In-Depth Information
T ABLE 12.1 GUI Container Classes
Container Class
Description
is used to hold components. Frames, panels, and applets are its subclasses.
java.awt.Container
is a top-level container for holding other Swing user-interface components in Java GUI applications.
javax.swing.JFrame
javax.swing.JPanel
is an invisible container for grouping user-interface components. Panels can be nested. You can place
panels inside another panel. JPanel is also often used as a canvas to draw graphics.
is a base class for creating a Java applet using Swing components.
javax.swing.JApplet
is a popup window generally used as a temporary window to receive additional information from the
user or to provide notification to the user.
javax.swing.JDialog
12.3.3 GUI Helper Classes
The helper classes, such as Graphics , Color , Font , FontMetrics , Dimension , and
LayoutManager , are not subclasses of Component . They are used to describe the properties
of GUI components, such as graphics context, colors, fonts, and dimension, as described in
Table 12.2.
T ABLE 12.2
GUI Helper Classes
Helper Class
Description
is an abstract class that provides the methods for drawing strings, lines, and simple shapes.
java.awt.Graphics
deals with the colors of GUI components. For example, you can specify background or foreground
colors in components like JFrame and JPanel , or you can specify colors of lines, shapes, and
strings in drawings.
java.awt.Color
java.awt.Font
specifies fonts for the text and drawings on GUI components. For example, you can specify the
font type (e.g., SansSerif), style (e.g., bold), and size (e.g., 24 points) for the text on a button.
java.awt.FontMetrics
is an abstract class used to get the properties of the fonts.
java.awt.Dimension
encapsulates the width and height of a component (in integer precision) in a single object.
specifies how components are arranged in a container.
java.awt.LayoutManager
Note
The helper classes are in the java.awt package. The Swing components do not
replace all the classes in the AWT, only the AWT GUI component classes (e.g.,
Button , TextField , TextArea ). The AWT helper classes are still useful in GUI
programming.
12.3
Which class is the root of the Java GUI component classes? Is a container class a sub-
class of Component ? Which class is the root of the Swing GUI component classes?
Check
Point
12.4
Which of the following statements have syntax errors?
Component c1 = new Component();
JComponent c2 = new JComponent();
Component c3 = new JButton();
JComponent c4 = new JButton();
 
 
Search WWH ::




Custom Search