17.2. Creating a Window
A basic window in Java is represented by an object of the Window class, which is defined in the java.awt package. Objects of the Window class are hardly ever used directly since borders and a title bar are fairly basic prerequisites for a typical application window, and this class provides neither. The library class JFrame that is defined in the javax.swing package is a much more useful class for creating a window since, in addition to a title bar and a border, it provides a wealth of other facilities. Its superclasses are shown in Figure 17-3.
Figure 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'll 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. Since 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 will contain menu items; a toolbar will obviously contain 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. ...
Get Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.