Java Swing

  • By
  • September 6, 2022
  • JAVA Programming
Java Swing

Java Swing

Java Swing may be a part of Java Foundation Classes (JFC) that is used to create window-based applications. it’s built on top of AWT (Abstract Windowing Toolkit) API and entirely written in java.

Unlike AWT, Java Swing provides platform-independent and lightweight components.

The javax.swing package provides classes for java swing API like JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser, etc.

 

For Free, Demo classes Call: 020-71173125
Registration Link: Click Here!

 

Example

Let’s take an example of the swing where we create one button and add the function of the JFrame object which is inside the method of main()

import javax.swing.*;  

public class FirstSwingExample {  

public static void main(String[] args) {  

JFrame f=new JFrame();//creating instance of JFrame  

          

JButton b=new JButton(“click”);//creating instance of JButton  

b.setBounds(130,100,100, 40);//x axis, y axis, width, height  

          

f.add(b);//adding button in JFrame  

          

f.setSize(400,500);//400 width and 500 height  

f.setLayout(null);//using no layout managers  

f.setVisible(true);//making the frame visible  

}  

}  

Here we can see one more example of JFrame with help of constructor

import javax.swing.*;  

public class Simple {  

JFrame f;  

Simple(){  

f=new JFrame();//creating instance of JFrame  

          

JButton b=new JButton(“click”);//creating instance of JButton  

b.setBounds(130,100,100, 40);  

          

f.add(b);//adding button in JFrame  

          

f.setSize(400,500);//400 width and 500 height  

f.setLayout(null);//using no layout managers  

f.setVisible(true);//making the frame visible  

}  

  

public static void main(String[] args) {  

new Simple();  

}  

}  

As we can see that in this example we are setting the bound where we are set the x axis y axis width and height

 

For Free, Demo classes Call: 020-71173125
Registration Link: Click Here!

 

Let us take one more example with the inheritance concept:

import javax.swing.*;  

public class Simple2 extends JFrame{//inheriting JFrame  

JFrame f;  

Simple2(){  

JButton b=new JButton(“click”);//create button  

b.setBounds(130,100,100, 40);  

          

add(b);//adding button on frame  

setSize(400,500);  

setLayout(null);  

setVisible(true);  

}  

public static void main(String[] args) {  

new Simple2();  

}}  

Swing has four times which contains user interface contents like AWT and we can say it’s part of the distribution of java standards. But in today’s world where requirements of clients are increasing as compared AWT has some limitations that’s why not capable to give the contents required for business applications. It contains very less bugs and that’s why it does take up a lot of resources when we compare to available data. Don’t spend time searching for Java Course in Pune and  Learn Java with SevenMentor Pvt Ltd and pave the way to a successful, lucrative, and prospering career as a Java programmer. 

Swing contains a set of APIs

it Provided Graphical User Interfaces to design in another unique way

swing has an extended library known as AWT

which contains newly launched and improved contents swings can also be used for building the standalone GUL applications where we can provide servlets and applets due to using these components the application will work differently not in a common way

we can say that swing can work as a model or view also if we implement as an architecture

swing is more portable where we can shift the data from AWT from one platform to another platform but we need to remember that swing contents are not dependent so we can conclude that they are light weighted and can transfer from one to another.

Many developers think that JFC and swing have similar properties but its not true

JFC contains Swing [A UI component package] and quite several other items:

Accessibility features: Aimed at developing GUI’s for users with disabilities

The Desktop Colors Features been Firstly introduced in Java 1.1

The Java 2D: this type Improved colors, images, and also texts support for better visualization

Features 

Pluggable look and feel

Uses MVC architecture

Lightweight Components

Platform Independent

 

For Free, Demo classes Call: 020-71173125
Registration Link: Click Here!

 

As we discussed above java never depends on any platform because it run on the client side where the look of GUL is good and feels owned and delivered by the specific platform it means it cant disturb at the server side or developers side

Lightweight Components: if we start with our first version of java development toolkit that was lightweight so due to the=is feature they are independent workly that’s why in swing these parts are included due to that it feels free and looks good

Pluggable Look and Feel: This type gives customer to switch the result and realize that contents of the swing are included while restarting the app the library which provides such parts are worldwide you can take them from anywhere because they are available everywhere. SevenMentor  Java Classes in Pune is ideal for both fresher and experienced professionals interested in a career as a Java developer in the software industry.

So here this is shot information about java swing which contains almost useful data.

 

Author:- Jyotsna Binjwe

Call the Trainer and Book your free demo class for now!!!

© Copyright 2020 | Sevenmentor Pvt Ltd.

 

Submit Comment

Your email address will not be published. Required fields are marked *

*
*