Swing is a Java Foundation Classes [JFC] framework and an Abstract Window Toolkit [AWT] extension. Swing has much-improved functionality over AWT, including additional components, expanded component features, and superior event management with drag-and-drop support. Unlike AWT, Java Swing provides platform-independent and lightweight components.
Java AWT | Java Swing |
---|---|
AWT components are platform-dependent. | Java swing components are platform-independent. |
AWT components are heavyweight. | Swing components are lightweight. |
AWT doesn’t support pluggable look and feel. | Swing supports a pluggable look and feel. |
AWT provides fewer components than Swing. | Tables, lists, scrollpanes, colorpicker, tabbedpane, and other more powerful components are available in Swing. |
AWT does not adhere to the MVC (Model View Controller) paradigm, in which the model represents data, the view provides presentation, and the controller serves as an interface between the model and the view. | Swing follows MVC. |
Component | A Component is the Abstract base class for SWING’s non-menu user interface controls. Components are objects that have graphical representations. |
Container | A Container is a component that holds SWING Components. |
JComponent | A JComponent is a foundational class for all swing UI Components. To use a JComponent-derived swing component, the component must be in a containment hierarchy whose root is a top-level Swing container. |
JLabel | A JLabel is an object component that is used to place text in a container. |
JButton | This class generates a button with a label. |
JColorChooser | A JColorChooser is a set of controls that allows the user to manipulate and select a color. |
JCheckBox | A JCheckBox is a graphical (GUI) component that can be on (true) or off (false). |
JRadioButton | The JRadioButton class is a graphical (GUI) component that can be on (true) or off (false). within the group |
JList | With a scrolling list of text objects, a JList component represents the user. |
JComboBox | JComboBox is a component. Displays a menu of options to the user. |
JTextField | A JTextField object is a text component that lets you change a single line of text. |
JPasswordField | A JPasswordField object is a text component designed specifically for password entering. |
JTextArea | A JTextArea object is a text component that allows you to modify many lines of text at once. |
Imagelcon | An ImageIcon control is an Icon interface implementation that paints Icons from images. |
JScrollbar | A JScrollbar control represents a scroll bar component that allows users to select from a range of values. |
JOptionPane | JOptionPane is a collection of basic dialogue windows that prompt users to enter a value or Something. |
JFileChooser | It Controls a JFileChooser, which depicts a dialogue box from which the user can select a file. |
JProgressBar | As the task progresses towards completion, the progress bar displays the percentage of the task on its completion |
JSlider | A JSlider is a class that allows the user to select a value graphically (GUI) by moving a knob within a specified interval. |
JSpinner | A JSpinner is a single-line input field that allows the user to select from an ordered sequence by using a number or an object value. |
import javax.swing.*; //importing swing package
import javax.swing.*; //importing swing package
import java.awt.*; //importing awt package
public class Coderz
{
JFrame jf;
public Coderz() {
jf = new JFrame("MyWindow"); //Creating a JFrame with name MyWindow
JButton btn = new JButton("Say Hello");//Creating a Button named Say Hello
jf.add(btn); //adding button to frame
jf.setLayout(new FlowLayout()); //setting layout using FlowLayout object
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setting close operation.
jf.setSize(400, 400); //setting size
jf.setVisible(true); //setting frame visibility
}
public static void main(String[] args)
{
new Coderz();
}
}
Note: also read about the AWT (Abstract Window Toolkit) in Java- II
If you like my post, please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…