Basic
Controls
Layout
Java swing consists of a set of components or widgets that are used to develop Graphical User Interface Applications. Java swing is a part of JFC (Java Foundation Class ). JFC consist of AWT, swing, and java2D. Basically there are two types of widget toolkits Light Weight and Heavy Weight. Java Swing is Lightweight GUI Toolkit that includes Buttons, Textboxes, etc…
Java Swing components are platform-independent. Swing are pluggable look and feel swing follows MVC framework. In Java Swing Container class plays an important role. Container class holds all the widgets. Container class divided in three type’s panel, Frame and Dialog.
To develop java GUI application java supports two technologies Java Swing and AWT. Compared with java AWT swing is richer in terms of components. Swings provide additional functionalities and added components to replace AWT. A most important feature of the swing is its components are platform-independent. Java swing uses MVC framework thus it provides more flexible UI. Swing components are lightweight components. Java swings are built-in double buffering. Swing components are different look and feel.
Java swing is used to develop desktop applications like billing or inventory applications, real time applications to manage and control mechanical devices. Swings is also used to develop some mobile applications like gaming, calculators, etc…
It also supports to develop a network-based application to manage clients in the network. These are very few examples of java swing uses since its platform-independent these benefits develop applications that run on any platform.
Simple java swing program to create a form for Student Registration.
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class StudentRegistration
{
public static void main(String[] args) {
Frame frame = new JFrame("Student Registration");
frame.setSize(350, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);
frame.setVisible(true);
}
private static void placeComponents(JPanel panel)
{
panel.setLayout(null);
JLabel userLabel1 = new JLabel("First Name");
userLabel1.setBounds(10,20,80,25);
panel.add(userLabel1);
JLabel userLabel2 = new JLabel("Last Name");
userLabel2.setBounds(10,50,100,25);
panel.add(userLabel2);
JLabel userLabel3 = new JLabel("Email ID");
userLabel3.setBounds(10,80,80,25);
panel.add(userLabel3);
JLabel userLabel4 = new JLabel("Phone No.");
userLabel4.setBounds(10,110,80,25);
panel.add(userLabel4);
JTextField fname = new JTextField(20);
fname.setBounds(100,50,165,25);
panel.add(fname);
JTextField lName = new JTextField(20);
lName.setBounds(100,20,165,25);
panel.add(lName);
JTextField email = new JTextField(20);
email.setBounds(100,80,165,25);
panel.add(email);
JTextField phNO = new JTextField(20);
phNO.setBounds(100,110,165,25);
panel.add(phNO);
JButton loginButton = new JButton("Register");
loginButton.setBounds(10, 160, 80, 25);
panel.add(loginButton);
JButton clearButton = new JButton("clear");
clearButton.setBounds(100, 160, 80, 25);
panel.add(clearButton);
}
}
Output:
Some basic knowledge about java programming and listener is a must while working with java swing. At some extent java event listener of AWT components and packages is necessary. Basic knowledge regarding form designing and alignment is also required. Netbeans IDE is well suited to develop desktop GUI applications using swings.
Target audience includes software professionals and beginners who are willing to learn java swings. Since its easier to design GUI application compared to AWT for beginners who are willing to learn form design or desktop application swings is the easiest way.
Web development, programming languages, Software testing & others
This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy
Web development, programming languages, Software testing & others
Call Our Course Advisors
IN : +91-8800880140