Principle 13.2.3. PROGRAMMING TIP: Swing Documentation.
Complete documentation of the Swing classes is available at https://docs.oracle.com/javase/7/docs/api/javax/swing/package-summary.html.
JApplet
, JDialog
, JFrame
, and JWindow
—are direct subclasses of their corresponding AWT counterparts. These are the top-level GUI windows.java.awt.Component
and java.awt.Container
. As you can see, the names of Swing and AWT components are very similar. Swing components that have corresponding AWT components have names that begin with “J.”JApplet
, JDialog
, JFrame
, and JWindow
—are defined as extensions to their AWT counterparts. This means that Swing-based GUIs are still dependent on the AWT. Java programs need to have some way to map their windows to the windowing system used on the native (Windows, Unix, or Macintosh) platform. The AWT’s top-level windows—Window
, Frame
, Dialog
, and Panel
—provide that mapping.JComponent
class, which is the basis for all Swing components, is derived from java.awt.Container
. There are many more such dependencies. Fundamentally, Swing components are based on the AWT.java.\-awt.FlowLayout
), fonts (java.awt.Font
), colors ( java.awt.Color
), and other non-component classes that are defined in the AWT. There is just no way to design a GUI without using AWT classes. Therefore, the programs presented in this and subsequent chapters will use Swing components instead of corresponding AWT components, but they also will use layouts and other elements from the AWT.javax.swing.*
, which is imported by the code shown in this and subsequent chapters. Swing packages include the following:javax.swing.event.*
javax.swing.text.*
javax.swing.plaf.*
javax.swing.event
package defines the various Swing events and their listeners, such as the MenuEvent
and the MenuListener
. (In the AWT, the AWT events and listeners were defined in java.awt.event
.)javax.swing.text
package contains the classes for JTextField
and JTextComponent
. The Swing text components are more complex than their AWT counterparts. For example, one of their important features is the ability to undo changes made to the text they contain. This feature is crucial for building sophisticated word-processing applications.javax.swing.plaf
package contains Swing’s look-and-feel classes. The term plaf is an acronym for pluggable look and feel. It refers to the fact that changing an application’s look and feel is a simple matter of “plugging in” a different plaf model. Changing how a program looks does not change what it does.JButton
, the class that defines the button control, there will be a separate class responsible for drawing the button on the screen. The drawing class will control the button’s color, shape, and other characteristics of its appearance.javax.swing.plaf.motif
package contains the classes that implement the Motif interface, a common Unix-based interface. The javax.swing.plaf.windows
packages contains classes that support a Windows look and feel, and the javax.swing.plaf.metal
package provides classes that support the Metal interface, a Java look and feel. These classes know how to draw each component and how to react to mouse, keyboard, and other events associated with these components.