1. the biggest difference between swing and AWT: swing is designed for the GUI application development of eager forms, providing excellent support for Java cross-platform features. it has no local code and is not affected by the operating system. It achieves real cross-platform applications and even provides other features not supported by the local window system. therefore, it is more practical than AWT and has a more refined appearance than AWT.
AWT only provides basic components, making many designs complex and failing to maintain consistent display styles on different platforms. for example, if a button object is created, a button (buttonpeer) is created together with its object, and then the button object will request the underlying operating system to create a real button. that is, run on Windows NT. If the button is created on Windows NT and executed on Linux, the button is created on Linux. therefore, the AWT component exterior will be affected by the underlying operating system. 2. swing features: (1 ). swing is implemented by 100% pure Java, and the swing component is a lightweight (light-weight) component implemented by Java. It does not have local code and does not rely on the support of the operating system, this is the biggest difference between it and the AWT component. Since the AWT component is implemented through peer implementation related to a specific platform, swing is more practical than the AWT component. Swing performs the same on different platforms and has the ability to provide other features not supported by the local window system.
(2 ). swing adopts a MVC design paradigm, namely, "Model-View-controller", where the model is used to save the content and the view is used to display the content, the controller is used to control user input.
(3). The Swing exterior feel adopts the pluggable exterior feel (Pluggable look and feel, PL & F) 3.Swing class hierarchy
In the javax. Swing package, two types of components are defined: top-level containers (jframe, japplet, jdialog and jwindow) and lightweight components. Swing components are both direct and indirect subclasses of the container class of AWT.
Java. AWT. Component
-Java. AWT. Container
-Java. AWT. Window
-Java. AWT. Frame-javax.swing.JFrame
-Javax. Dialog-javax.swing.JDialog
-Javax. Swing. jwindow
-Java. AWT. Applet-javax.swing.JApplet
-Javax. Swing. Box
-Javax. Swing. jcomponet
A swing package is a part of jfc (Java foundation classes) and consists of many packages.
Package |
Description |
Com. Sum. Swing. plaf. Motif |
User Interface representative class, which implements motif interface style |
Com. Sum. java. Swing. plaf. Windows |
User Interface representative classes, which implement Windows interface styles |
Javax. Swing |
Swing components and tools |
Javax. Swing. Border |
Border of swing lightweight components |
Javax. Swing. colorchooser |
Jcolorchooser Support class/interface |
Javax. Swing. Event |
Event and listener class |
Javax. Swing. filechooser |
Jfilechooser Support class/interface |
Javax. Swing. Pending |
Not fully implemented swing Components |
Javax. Swing. plaf |
Abstract class that defines the behavior represented by the UI |
Javax. Swing. plaf. Basic |
Base class that implements all common functions of standard interface styles |
Javax. Swing. plaf. Metal |
User Interface representative classes, which implement metal interface styles |
Javax. Swing. Table |
Jtable component |
Javax. Swing. Text |
Supports document display and editing. |
Javax.swing.text.html |
Allows you to display and edit HTML documents. |
Javax.swing.text.html. parser |
Analyzer for HTML documents |
Javax. Swing. Text. rtf |
Allows you to display and edit RTF files. |
Javax. Swing. Tree |
Jtree component support Class |
Javax. Swing. Undo |
Operation canceled |
4.MVC (Model-View-Control) Architecture
Model: The place where the component data is stored. For example, the model in jcheckbox stores the values of all options and uses the Boolean value. The jtable model stores the data of all tables.
View: displays the component appearance.
Controller: processes user operations on components and stores the changed data in the model.
To simplify the component design, view and controller are integrated in the swing component. Each component has a related Separation Model and Its Interface (including views and controls ). For example, the button jbutton has a separated model buttonmodel object that stores its status. The component model is automatically set. For example, jbutton is generally used instead of the buttonmodel object. In addition, you can create your own model for components by subclass of the model class or by implementing appropriate interfaces. Associate the data model with the component using the setmodel () method.
The model in the swing component can be divided into three types:
(1). store the data that will be used for operation in the component.
(2). Storage and control component operation mode data
(3) Data modes of the storage component itself
MVC is a common idea for creating graphical user interfaces in existing programming languages. The idea is to separate the data content and display methods, this makes the data display more flexible and diverse. For example, if the number of students in each class in a certain grade is data, the display methods are diverse. You can use a bar chart, a pie chart, or a direct data output. Therefore, data and display methods should be separated during the design, which is very helpful for achieving a variety of display.