SlideShare a Scribd company logo
Module 3
SWING
swing
• Java Swing is a lightweight GUI toolkit for building window-based applications. Here are some
key points about it:
Platform-Independent: Unlike AWT (Abstract Windowing Toolkit), Swing components are
platform-independent.
Lightweight: Swing components are lightweight, making them efficient for creating graphical
interfaces.
Rich Components: Swing provides powerful components like buttons, text fields, radio buttons,
menus, and more.
MVC Architecture: Swing follows the Model-View-Controller (MVC) pattern, separating data,
presentation, and control.
swing
• Swing is a Java Foundation Classes [JFC] library and an extension of the Abstract Window Toolkit [AWT].
Hierarchy of Java Swing classes
Commonly used Methods of Component class
simple swing example where we are creating one button and adding it on the JFrame object inside the
main() method.
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
}
}
Swings in java to develop applications in java
GUI?
• A system of interactive visual components for a computer or system
software is called a GUI (graphical user interface).
• GUI is the interface that uses graphical elements to let people interact
as per requirement with electronic devices including computers,
laptops, tablets, and smartphones.
import javax.swing.*;
public class example{
public static void main(String args[]) {
JFrame a = new JFrame("example");
JButton b = new JButton("click me");
b.setBounds(40,90,85,20);
a.add(b);
a.setSize(300,300);
a.setLayout(null);
a.setVisible(true);
}
}
Output:
JTextField Class
It inherits the JTextComponent class and it is used to allow editing of single line text.
import javax.swing.*;
public class example{
public static void main(String args[]) {
JFrame a = new JFrame("example");
JTextField b = new JTextField("edureka");
b.setBounds(50,100,200,30);
a.add(b);
a.setSize(300,300);
a.setLayout(null);
a.setVisible(true);
}
}
JScrollBar Class
It is used to add scroll bar, both horizontal and vertical.
import javax.swing.*;
class example{
example(){
JFrame a = new JFrame("example");
JScrollBar b = new JScrollBar();
b.setBounds(90,90,40,90);
a.add(b);
a.setSize(300,300);
a.setLayout(null);
a.setVisible(true);
}
public static void main(String args[]){
new example();
}
}
JList Class
It inherits JComponent class, the object of JList class represents a list of text items.
import javax.swing.*;
public class Example
{
Example(){
JFrame a = new JFrame("example");
DefaultListModel<String> l = new DefaultListModel< >();
l.addElement("first item");
l.addElement("second item");
JList<String> b = new JList< >(l);
b.setBounds(100,100,75,75);
a.add(b);
a.setSize(400,400);
a.setVisible(true);
a.setLayout(null);
}
public static void main(String args[])
{
new Example();
}
}
JLabel Class
It is used for placing text in a container. It also inherits JComponent class.
import javax.swing.*;
public class Example{
public static void main(String args[])
{
JFrame a = new JFrame("example");
JLabel b1;
b1 = new JLabel("edureka");
b1.setBounds(40,40,90,20);
a.add(b1);
a.setSize(400,400);
a.setLayout(null);
a.setVisible(true);
}
}
JComboBox Class
It inherits the JComponent class and is used to show pop up menu of choices.
import javax.swing.*;
public class Example{
JFrame a;
Example(){
a = new JFrame("example");
string courses[] = { "core java","advance java", "java servlet"};
JComboBox c = new JComboBox(courses);
c.setBounds(40,40,90,20);
a.add(c);
a.setSize(400,400);
a.setLayout(null);
a.setVisible(true);
}
public static void main(String args[])
{
new Example();
}
}
Example 2: Write a program to create three buttons with caption OK, SUBMIT, CANCEL

More Related Content

Similar to Swings in java to develop applications in java (20)

DOC
java swing notes in easy manner for UG students
RameshPrasadBhatta2
 
PDF
Z blue introduction to gui (39023299)
Narayana Swamy
 
PPT
Java Swing Handson Session (1).ppt
ssuser076380
 
PDF
Swing
Fahim Khan
 
PDF
Swing
Fahim Khan
 
PPTX
Java swing
ssuser3a47cb
 
PPTX
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Salini P
 
PPTX
Computer Programming NC III - Java Swing.pptx
jonathancapitulo2
 
PPTX
UNIT 2 SWIGS for java programing by .pptx
st5617067
 
PPT
Basic using of Swing in Java
suraj pandey
 
PPSX
Basic of Java Netbeans
Shrey Goswami
 
PPTX
Swing !!! y shikhar!!
shikhar199
 
PPT
13457272.ppt
aptechaligarh
 
PPTX
Swings
Balwinder Kumar
 
PDF
Ebook Pdf O Reilly Java Swing
owambacq
 
PPT
Java lecture
Nataraj Dg
 
PDF
Unit-2 swing and mvc architecture
Amol Gaikwad
 
PPT
Windows Programming with Swing
backdoor
 
PPTX
JavaSwingndAWTProgrammingforBeginner.pptx
cluttertans
 
PDF
The java swing_tutorial
sumitjoshi01
 
java swing notes in easy manner for UG students
RameshPrasadBhatta2
 
Z blue introduction to gui (39023299)
Narayana Swamy
 
Java Swing Handson Session (1).ppt
ssuser076380
 
Swing
Fahim Khan
 
Swing
Fahim Khan
 
Java swing
ssuser3a47cb
 
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
Salini P
 
Computer Programming NC III - Java Swing.pptx
jonathancapitulo2
 
UNIT 2 SWIGS for java programing by .pptx
st5617067
 
Basic using of Swing in Java
suraj pandey
 
Basic of Java Netbeans
Shrey Goswami
 
Swing !!! y shikhar!!
shikhar199
 
13457272.ppt
aptechaligarh
 
Ebook Pdf O Reilly Java Swing
owambacq
 
Java lecture
Nataraj Dg
 
Unit-2 swing and mvc architecture
Amol Gaikwad
 
Windows Programming with Swing
backdoor
 
JavaSwingndAWTProgrammingforBeginner.pptx
cluttertans
 
The java swing_tutorial
sumitjoshi01
 

Recently uploaded (20)

PPTX
Big Data and Data Science hype .pptx
SUNEEL37
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
smart lot access control system with eye
rasabzahra
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Big Data and Data Science hype .pptx
SUNEEL37
 
Design Thinking basics for Engineers.pdf
CMR University
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
MRRS Strength and Durability of Concrete
CivilMythili
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Thermal runway and thermal stability.pptx
godow93766
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
smart lot access control system with eye
rasabzahra
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Ad

Swings in java to develop applications in java

  • 2. swing • Java Swing is a lightweight GUI toolkit for building window-based applications. Here are some key points about it: Platform-Independent: Unlike AWT (Abstract Windowing Toolkit), Swing components are platform-independent. Lightweight: Swing components are lightweight, making them efficient for creating graphical interfaces. Rich Components: Swing provides powerful components like buttons, text fields, radio buttons, menus, and more. MVC Architecture: Swing follows the Model-View-Controller (MVC) pattern, separating data, presentation, and control.
  • 3. swing • Swing is a Java Foundation Classes [JFC] library and an extension of the Abstract Window Toolkit [AWT].
  • 4. Hierarchy of Java Swing classes
  • 5. Commonly used Methods of Component class
  • 6. simple swing example where we are creating one button and adding it on the JFrame object inside the main() method. 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 } }
  • 8. GUI? • A system of interactive visual components for a computer or system software is called a GUI (graphical user interface). • GUI is the interface that uses graphical elements to let people interact as per requirement with electronic devices including computers, laptops, tablets, and smartphones.
  • 9. import javax.swing.*; public class example{ public static void main(String args[]) { JFrame a = new JFrame("example"); JButton b = new JButton("click me"); b.setBounds(40,90,85,20); a.add(b); a.setSize(300,300); a.setLayout(null); a.setVisible(true); } } Output:
  • 10. JTextField Class It inherits the JTextComponent class and it is used to allow editing of single line text. import javax.swing.*; public class example{ public static void main(String args[]) { JFrame a = new JFrame("example"); JTextField b = new JTextField("edureka"); b.setBounds(50,100,200,30); a.add(b); a.setSize(300,300); a.setLayout(null); a.setVisible(true); } }
  • 11. JScrollBar Class It is used to add scroll bar, both horizontal and vertical. import javax.swing.*; class example{ example(){ JFrame a = new JFrame("example"); JScrollBar b = new JScrollBar(); b.setBounds(90,90,40,90); a.add(b); a.setSize(300,300); a.setLayout(null); a.setVisible(true); } public static void main(String args[]){ new example(); } }
  • 12. JList Class It inherits JComponent class, the object of JList class represents a list of text items. import javax.swing.*; public class Example { Example(){ JFrame a = new JFrame("example"); DefaultListModel<String> l = new DefaultListModel< >(); l.addElement("first item"); l.addElement("second item"); JList<String> b = new JList< >(l); b.setBounds(100,100,75,75); a.add(b); a.setSize(400,400); a.setVisible(true); a.setLayout(null); } public static void main(String args[]) { new Example(); } }
  • 13. JLabel Class It is used for placing text in a container. It also inherits JComponent class. import javax.swing.*; public class Example{ public static void main(String args[]) { JFrame a = new JFrame("example"); JLabel b1; b1 = new JLabel("edureka"); b1.setBounds(40,40,90,20); a.add(b1); a.setSize(400,400); a.setLayout(null); a.setVisible(true); } }
  • 14. JComboBox Class It inherits the JComponent class and is used to show pop up menu of choices. import javax.swing.*; public class Example{ JFrame a; Example(){ a = new JFrame("example"); string courses[] = { "core java","advance java", "java servlet"}; JComboBox c = new JComboBox(courses); c.setBounds(40,40,90,20); a.add(c); a.setSize(400,400); a.setLayout(null); a.setVisible(true); } public static void main(String args[]) { new Example(); } }
  • 15. Example 2: Write a program to create three buttons with caption OK, SUBMIT, CANCEL