![]() |
|||
![]() ![]() |
![]() |
|
![]() |
PackagesThe Swing component toolkit consists of over 250 pure Java classes and 75 interfaces contained in more than 10 packages. They are used to build lightweight user interfaces. Swing consists of nonuser-interface (non-UI) classes as well as the more familiar user-interface (UI) classes. The non-UI classes provide services and other operations for the UI classes. They do not display anything on screen. Examples of non-UI Swing classes are the events fired by Swing components and the Swing data model classes. The UI classes, such as buttons and labels, create visible components that applications can display on screen, and they can be combined to create a complete graphical user interface. The Swing UI components descend from the JComponent class, and all begin with the capital letter J. Swing packages that are typically used by developers when building GUIs are listed, and briefly explained, in the following sections.
The Swing Package: javax.swing This is the largest of the Swing packages consisting of approximately 100 classes and 25 interfaces. The majority of the UI classes (the J classes) are contained in this package. The exceptions are JTableHeader, implemented in the javax.swing.table package, and JTextComponent, implemented in the javax.swing.text package. Both of these packages are described shortly. Also contained in this package are high-level choice components. This type of component allows the user to visually choose a value from a fixed set of possible valueschoosing a color, for example. The components in this package are the primary focus of this book (see Figure 1.2). Examples of their use are given throughout.
The Basic Package: javax.swing.plaf.basic The Basic package contains classes that define the default look-and-feel of Swing components. By extending these classes, components with a customized PL&F can be developed. This is the second largest package in terms of the number of classes, containing approximately 40 classes. The high number of classes should give a feel for the amount of work required to develop a complete PL&F. The Border Package: javax.swing.border The Border package contains the Border interface and nine classes that implement this interface. Typically classes in this package are not instantiated directly; instead, instances are obtained via methods in the BorderFactory class contained in the javax.swing package. However, the constants defined in the classes in this package are often used when obtaining borders from the factory. Classes in this package can be extended to create a specialized border. The Border package and the borders contained in the JFC are presented in Chapter 5, Basic Components. The Event Package: javax.swing.event The Event package defines events specific to Swing components. The events defined in this package fill roles similar to those defined in the java.awt.event package. There are approximately 25 Swing-specific events. The events themselves and their associated Listener interfaces are defined in this package. Swing events are used by the various data models contained in the JFC. The events are presented with the classes that fire the particular event. The Multipackage: javax.swing.plaf.multi The Multipackage consists of multiplexing UI classes. These allow Swing components to have UIs provided by multiple user-interface factories. The Pluggable Look-and-Feel Package: javax.swing.plaf The PL&F package consists of classes that provide Swing components with pluggable look-and-feel capabilities. If a custom PL&F is being developed and the classes in the javax.swing.plaf.basic package cannot be extended, the abstract classes contained in this package can be used as a starting point. The JFC is shipped with three PL&Fs: the Windows PL&F contained in the com.sun.java.swing.plaf.windows package (see Figure 1.2), the Motif PL&F contained in the com.sun.java.swing.plaf.motif package (see Figure 1.3), and the Metal platform-neutral PL&F contained in the javax.swing.plaf.metal package (see Figure 1.4). The Macintosh PL&F contained in the com.sun.java.swing.plaf.mac package is available separately.
|
![]() |
|