Java Reference
In-Depth Information
addition to a title bar and a border, it provides a wealth of other facilities. Its superclasses are shown in Fig-
ure 17-3 .
FIGURE 17-3
The Component class is the grandmother of all component classes — it defines the basic properties and
methods shared by all components. You see later that all the Swing components have the Component class as
a base. The Container class adds the capability for a Component object to contain other components, which
is a frequent requirement. Because JFrame has Container as a superclass, a JFrame object can contain other
components. Beyond the obvious need for a window to be able to contain the components that represent the
GUI, a menu bar should contain menus, for example, which in turn contains menu items; a toolbar obviously
contains toolbar buttons; and there are many other examples. For this reason the Container class is also a
base for all the classes that define Swing components.
The Window class adds methods to the Container class that are specific to a window, such as the capab-
ility to handle events arising from user interaction with the window. The Frame class is the original class in
java.awt that provided a proper window with a title bar and a border, with which everyone is familiar. The
JFrame class adds functionality to the Frame class to support much more sophisticated facilities for drawing
and displaying other components. You can deduce from the hierarchy in the diagram how a JFrame object
can easily end up with its 200+ methods, as it has five superclasses from which it inherits members. You
aren't going to trawl through all these classes and methods. You just look into the ones you need in context
as you go along, and then see how they are applied in some examples. This teaches you the most important
methods in this class.
Framing a Window
You can display an application window simply by creating an object of type JFrame , calling a method for
the object to set the size of the window, and then calling a method to display the window. Executing the
following code fragment creates a window object and displays the window that it represents:
 
 
Search WWH ::




Custom Search