21-Java Swing
21-Java Swing
The view determines how the component is displayed on the screen, including any aspects of
the view that are affected by the current state of the model.
Swing uses a modified version of MVC that combines the view and the controller into a single
logical entity called the UI delegate.
Components
Swing components are derived from the JComponent class.
JComponent provides the functionality that is common to all components.
JComponent inherits the AWT classes Container and Component.
Thus, a Swing component is built on and compatible with an AWT component.
All of Swing’s components are represented by classes defined within the package
javax.swing.
Containers
Swing defines two types of containers.
The first are top-level containers: JFrame, JApplet, JWindow, and JDialog.
The second type of containers supported by Swing are lightweight containers. Lightweight
containers do inherit JComponent. An example of a lightweight container is JPanel, which is
a general-purpose container.
import javax.swing.*;
public class FirstSwingExample {
public static void main(String[] args) {
JFrame f=new JFrame();//creating instance of JFrame