SlideShare a Scribd company logo
Graphical User Interface
Introduction
• Swing library is an official Java GUI toolkit
released by Sun Microsystems
• Swing is a part of JFC, Java Foundation Classes
• Used to create Graphical user interfaces with
Java.
• It is a collection of packages for creating full
featured desktop applications.
• JFC consists of AWT, Swing, Accessibility, Java 2D,
and Drag and Drop.
• Swing was released in 1997 with JDK 1.2
Introduction (contd)
• Platform independent
• Customizable
• Extensible
• Configurable
• Lightweight
Swing API packages
• Swing API has 18 public packages
• javax.accessibility
• javax.swing
• javax.swing.border
• javax.swing.colorchooser
• javax.swing.event
• javax.swing.filechooser
• javax.swing.plaf
• javax.swing.plaf.basic
• javax.swing.plaf.metal
Swing API packages (contd)
• javax.swing.plaf.multi
• javax.swing.plaf.synth
• javax.swing.table
• javax.swing.text
• javax.swing.text.html
• javax.swing.text.html.parser
• javax.swing.text.rtf
• javax.swing.tree
• javax.swing.undo
Swing Components Hierarchy
Swing Components
Layout Management
• Java Swing toolkit has two kind of
components
– Container Components
– Children Components
• The containers group children into suitable
layouts
• To create layouts, we use layout managers
Layout Management (contd)
• BorderLayout
• BoxLayout
• CardLayout
• FlowLayout
• GridBagLayout
• GridLayout
• GroupLayout
• SpringLayout
Absolute Positioning
• If a container holds components whose size is not
affected by the container's size or by font, look-
and-feel, or language changes
• Creating a container without a layout manager
involves the following steps.
1.Set the container's layout manager to null by
calling setLayout(null).
2.Call the Component class's setbounds method for
each of the container's children.
3.Call the Component class's repaint method.
Absolute Positioning (contd)
• Creating containers with absolutely positioned
containers can cause problems if the window
containing the container is resized
FlowLayout
• The FlowLayout class provides a very simple
layout manager that is used, by default, by the
JPanel objects
• The FlowLayout class puts components in a row,
sized at their preferred size
• If the horizontal space in the container is too
small to put all the components in one row, the
FlowLayout class uses multiple rows
• If the container is wider than necessary for a row
of components, the row is, by default, centered
horizontally within the container
FlowLayout (contd)
• To specify that the row is to aligned either to
the left or right, use a FlowLayout constructor
that takes an alignment argument
– public FlowLayout(int align)
• Another constructor of the FlowLayout class
specifies how much vertical or horizontal padding
is put around the components
– public FlowLayout(int align, int hgap, int vgap)
Flow Layout (contd)
BorderLayout
• A BorderLayout object has five areas specified
by the BorderLayout constants:
– PAGE_START
– PAGE_END
– LINE_START
– LINE_END
– CENTER
BorderLayout (contd)
• If the window is enlarged, the center area gets
as much of the available space as possible
• Other areas expand only as much as necessary
to fill all available space
• Often a container uses only one or two of the
areas of the BorderLayout object — just the
center, or the center and the bottom.
BorderLayout (contd)
GridLayout
• A GridLayout object places components in a
grid of cells
• Each component takes all the available space
within its cell, and each cell is exactly the
same size
• If the window is resized, the GridLayout object
changes the cell size so that the cells are as
large as possible, given the space available to
the container
GridLayout (contd)
Event Handling
Introduction
• All GUI applications are event-driven
• An application reacts to different event types
which are generated during its life
• Events are generated mainly by the user of an
application
• But they can be generated by other means as
well. e.g. internet connection, window
manager, timer
Introduction (contd)
• In the event model, there are three participants:
– event source
– event object
– event listener
• The Event source is the object whose state changes and
generates Events
• The Event object (Event) encapsulates the state changes in
the event source
• The Event listener is the object that wants to be notified.
Event source object delegates the task of handling an event
to the event listener.
Event Object
• When something happens in the application, an
event object is created
• There are several types of events, e.g ActionEvent,
TextEvent, FocusEvent, ComponentEvent etc,
created under specific conditions.
• Event object has information about an event, that
has happened
Implementation
• There are several ways, how we can
implement event handling in Java Swing
toolkit
– Anonymous inner class
– Inner class
– Derived class
Anonymous Inner Class
• The button is the event source and it will
generate events
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
} });
• Here we register an action listener with the
button
• This way, the events are sent to the event
target
• The event target in our case is ActionListener
Inner Class
• The listener is defined inside an inner class, which
has a name
ButtonCloseListener listener = new ButtonCloseListener();
closeButton.addActionListener(listener);
• Here we have a non anonymous inner class
class ButtonCloseListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
} }
• The button listener is defined here.
Derived Class
• We create a MyButton class, that implements the action
listener
MyButton closeButton = new MyButton("Close");
• Now create the MyButton custom class
class MyButton extends JButton implements ActionListener {
• The MyButton class is extended from the JButton class and
implements the ActionListener interface
• This way, the event handling is managed within the
MyButton class.
addActionListener(this);
• Here we add the action listener to the MyButton class.
Adapter Classes
• Time consuming to define all interface
methods
• WindowListener has seven methods
• What if we only want to use one?
• Required to define all methods in interface
• Adapter class implements an interface
• Does anyone recognize a design pattern here?
• Default implementation ({ }, empty body) for
all methods
Adapter Classes (contd)
• You then extend adapter class,
• overriding methods for events you care about,
such as windowClosing.
• Has "is a" relationship with interface
• WindowAdapter is a WindowListener
• MouseAdapter is a MouseListener
Ad

More Related Content

What's hot (20)

java swing
java swingjava swing
java swing
Waheed Warraich
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
Jussi Pohjolainen
 
Swing
SwingSwing
Swing
Jaydeep Viradiya
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
kirupasuchi1996
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
suraj pandey
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
Chapter 1 swings
Chapter 1 swingsChapter 1 swings
Chapter 1 swings
Jafar Nesargi
 
Swings
SwingsSwings
Swings
Balwinder Kumar
 
Java swing
Java swingJava swing
Java swing
ssuser3a47cb
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
Gui in java
Gui in javaGui in java
Gui in java
Gaurav Raj
 
Complete java swing
Complete java swingComplete java swing
Complete java swing
jehan1987
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
28 awt
28 awt28 awt
28 awt
Prachi Vijh
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
OXUS 20
 
Jdbc
JdbcJdbc
Jdbc
Jaydeep Viradiya
 
Swings in java
Swings in javaSwings in java
Swings in java
Jyoti Totla
 
Awt
AwtAwt
Awt
Rakesh Patil
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Java
suraj pandey
 

Viewers also liked (18)

Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
Bivek Pakuwal
 
Java Swing
Java SwingJava Swing
Java Swing
Shraddha
 
Graphical User Interface
Graphical User InterfaceGraphical User Interface
Graphical User Interface
Deepa Ram Suthar
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
OXUS 20
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
francopw
 
java swing
java swingjava swing
java swing
vannarith
 
USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPT
vicci4041
 
Utilisation de ZK avec Java - Retour d’expérience
Utilisation de ZK avec Java - Retour d’expérienceUtilisation de ZK avec Java - Retour d’expérience
Utilisation de ZK avec Java - Retour d’expérience
louschwartz
 
Oracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensembleOracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensemble
ANASYS
 
MC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUAMC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUA
Sajid Mughal
 
Java swings
Java swingsJava swings
Java swings
Alisha Korpal
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transfer
Ankit Desai
 
Explorations in Creative Coding
Explorations in Creative CodingExplorations in Creative Coding
Explorations in Creative Coding
Eelco den Heijer
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
Shehrevar Davierwala
 
java swing programming
java swing programming java swing programming
java swing programming
Ankit Desai
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
OUM SAOKOSAL
 
User Interface Design @iRajLal
User Interface Design @iRajLalUser Interface Design @iRajLal
User Interface Design @iRajLal
Raj Lal
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
Bivek Pakuwal
 
Java Swing
Java SwingJava Swing
Java Swing
Shraddha
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
OXUS 20
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
francopw
 
USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPT
vicci4041
 
Utilisation de ZK avec Java - Retour d’expérience
Utilisation de ZK avec Java - Retour d’expérienceUtilisation de ZK avec Java - Retour d’expérience
Utilisation de ZK avec Java - Retour d’expérience
louschwartz
 
Oracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensembleOracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensemble
ANASYS
 
MC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUAMC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUA
Sajid Mughal
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transfer
Ankit Desai
 
Explorations in Creative Coding
Explorations in Creative CodingExplorations in Creative Coding
Explorations in Creative Coding
Eelco den Heijer
 
java swing programming
java swing programming java swing programming
java swing programming
Ankit Desai
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
OUM SAOKOSAL
 
User Interface Design @iRajLal
User Interface Design @iRajLalUser Interface Design @iRajLal
User Interface Design @iRajLal
Raj Lal
 
Ad

Similar to Swing and Graphical User Interface in Java (20)

JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
java-programming GUI- Event Handling.pdf
java-programming GUI- Event Handling.pdfjava-programming GUI- Event Handling.pdf
java-programming GUI- Event Handling.pdf
doraeshin04
 
Events1
Events1Events1
Events1
Nuha Noor
 
EventHandling.pptx
EventHandling.pptxEventHandling.pptx
EventHandling.pptx
VamsiKrishna424209
 
Mod_5 of Java 5th module notes for ktu students
Mod_5 of Java 5th module notes for ktu studentsMod_5 of Java 5th module notes for ktu students
Mod_5 of Java 5th module notes for ktu students
heytherenewworld
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
MugiiiReee
 
Android - Activity, Services
Android - Activity, ServicesAndroid - Activity, Services
Android - Activity, Services
Dr Karthikeyan Periasamy
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
usvirat1805
 
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfjunit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
sangeethajadhav9901
 
Creating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interfaceCreating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interface
pikachu02434
 
Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
SAGARDAVE29
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
SivaSankari36
 
Awt event
Awt eventAwt event
Awt event
Vijay Kumar
 
14a-gui.ppt
14a-gui.ppt14a-gui.ppt
14a-gui.ppt
DrDGayathriDevi
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Event Handling in Java as per university
Event Handling in Java as per universityEvent Handling in Java as per university
Event Handling in Java as per university
Sanjay Kumar
 
03_GUI.ppt
03_GUI.ppt03_GUI.ppt
03_GUI.ppt
DrDGayathriDevi
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
Dr. SURBHI SAROHA
 
graphical user interface using python easy
graphical user interface using python easygraphical user interface using python easy
graphical user interface using python easy
ravipati23phd7217
 
09events
09events09events
09events
Waheed Warraich
 
java-programming GUI- Event Handling.pdf
java-programming GUI- Event Handling.pdfjava-programming GUI- Event Handling.pdf
java-programming GUI- Event Handling.pdf
doraeshin04
 
Mod_5 of Java 5th module notes for ktu students
Mod_5 of Java 5th module notes for ktu studentsMod_5 of Java 5th module notes for ktu students
Mod_5 of Java 5th module notes for ktu students
heytherenewworld
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
MugiiiReee
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
usvirat1805
 
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfjunit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
sangeethajadhav9901
 
Creating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interfaceCreating GUI.pptx Gui graphical user interface
Creating GUI.pptx Gui graphical user interface
pikachu02434
 
Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
SAGARDAVE29
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
SivaSankari36
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Event Handling in Java as per university
Event Handling in Java as per universityEvent Handling in Java as per university
Event Handling in Java as per university
Sanjay Kumar
 
graphical user interface using python easy
graphical user interface using python easygraphical user interface using python easy
graphical user interface using python easy
ravipati23phd7217
 
Ad

More from babak danyal (20)

applist
applistapplist
applist
babak danyal
 
Easy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client SocketsEasy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client Sockets
babak danyal
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
babak danyal
 
Tcp sockets
Tcp socketsTcp sockets
Tcp sockets
babak danyal
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the des
babak danyal
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network security
babak danyal
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systems
babak danyal
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systems
babak danyal
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systems
babak danyal
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systems
babak danyal
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systems
babak danyal
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systems
babak danyal
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systems
babak danyal
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systems
babak danyal
 
Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signa
babak danyal
 
Lecture9 Signal and Systems
Lecture9 Signal and SystemsLecture9 Signal and Systems
Lecture9 Signal and Systems
babak danyal
 
Lecture9
Lecture9Lecture9
Lecture9
babak danyal
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniques
babak danyal
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Security
babak danyal
 
Problems at independence
Problems at independenceProblems at independence
Problems at independence
babak danyal
 
Easy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client SocketsEasy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client Sockets
babak danyal
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
babak danyal
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the des
babak danyal
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network security
babak danyal
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systems
babak danyal
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systems
babak danyal
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systems
babak danyal
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systems
babak danyal
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systems
babak danyal
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systems
babak danyal
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systems
babak danyal
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systems
babak danyal
 
Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signa
babak danyal
 
Lecture9 Signal and Systems
Lecture9 Signal and SystemsLecture9 Signal and Systems
Lecture9 Signal and Systems
babak danyal
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniques
babak danyal
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Security
babak danyal
 
Problems at independence
Problems at independenceProblems at independence
Problems at independence
babak danyal
 

Recently uploaded (20)

Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 

Swing and Graphical User Interface in Java

  • 2. Introduction • Swing library is an official Java GUI toolkit released by Sun Microsystems • Swing is a part of JFC, Java Foundation Classes • Used to create Graphical user interfaces with Java. • It is a collection of packages for creating full featured desktop applications. • JFC consists of AWT, Swing, Accessibility, Java 2D, and Drag and Drop. • Swing was released in 1997 with JDK 1.2
  • 3. Introduction (contd) • Platform independent • Customizable • Extensible • Configurable • Lightweight
  • 4. Swing API packages • Swing API has 18 public packages • javax.accessibility • javax.swing • javax.swing.border • javax.swing.colorchooser • javax.swing.event • javax.swing.filechooser • javax.swing.plaf • javax.swing.plaf.basic • javax.swing.plaf.metal
  • 5. Swing API packages (contd) • javax.swing.plaf.multi • javax.swing.plaf.synth • javax.swing.table • javax.swing.text • javax.swing.text.html • javax.swing.text.html.parser • javax.swing.text.rtf • javax.swing.tree • javax.swing.undo
  • 8. Layout Management • Java Swing toolkit has two kind of components – Container Components – Children Components • The containers group children into suitable layouts • To create layouts, we use layout managers
  • 9. Layout Management (contd) • BorderLayout • BoxLayout • CardLayout • FlowLayout • GridBagLayout • GridLayout • GroupLayout • SpringLayout
  • 10. Absolute Positioning • If a container holds components whose size is not affected by the container's size or by font, look- and-feel, or language changes • Creating a container without a layout manager involves the following steps. 1.Set the container's layout manager to null by calling setLayout(null). 2.Call the Component class's setbounds method for each of the container's children. 3.Call the Component class's repaint method.
  • 11. Absolute Positioning (contd) • Creating containers with absolutely positioned containers can cause problems if the window containing the container is resized
  • 12. FlowLayout • The FlowLayout class provides a very simple layout manager that is used, by default, by the JPanel objects • The FlowLayout class puts components in a row, sized at their preferred size • If the horizontal space in the container is too small to put all the components in one row, the FlowLayout class uses multiple rows • If the container is wider than necessary for a row of components, the row is, by default, centered horizontally within the container
  • 13. FlowLayout (contd) • To specify that the row is to aligned either to the left or right, use a FlowLayout constructor that takes an alignment argument – public FlowLayout(int align) • Another constructor of the FlowLayout class specifies how much vertical or horizontal padding is put around the components – public FlowLayout(int align, int hgap, int vgap)
  • 15. BorderLayout • A BorderLayout object has five areas specified by the BorderLayout constants: – PAGE_START – PAGE_END – LINE_START – LINE_END – CENTER
  • 16. BorderLayout (contd) • If the window is enlarged, the center area gets as much of the available space as possible • Other areas expand only as much as necessary to fill all available space • Often a container uses only one or two of the areas of the BorderLayout object — just the center, or the center and the bottom.
  • 18. GridLayout • A GridLayout object places components in a grid of cells • Each component takes all the available space within its cell, and each cell is exactly the same size • If the window is resized, the GridLayout object changes the cell size so that the cells are as large as possible, given the space available to the container
  • 21. Introduction • All GUI applications are event-driven • An application reacts to different event types which are generated during its life • Events are generated mainly by the user of an application • But they can be generated by other means as well. e.g. internet connection, window manager, timer
  • 22. Introduction (contd) • In the event model, there are three participants: – event source – event object – event listener • The Event source is the object whose state changes and generates Events • The Event object (Event) encapsulates the state changes in the event source • The Event listener is the object that wants to be notified. Event source object delegates the task of handling an event to the event listener.
  • 23. Event Object • When something happens in the application, an event object is created • There are several types of events, e.g ActionEvent, TextEvent, FocusEvent, ComponentEvent etc, created under specific conditions. • Event object has information about an event, that has happened
  • 24. Implementation • There are several ways, how we can implement event handling in Java Swing toolkit – Anonymous inner class – Inner class – Derived class
  • 25. Anonymous Inner Class • The button is the event source and it will generate events closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); • Here we register an action listener with the button • This way, the events are sent to the event target • The event target in our case is ActionListener
  • 26. Inner Class • The listener is defined inside an inner class, which has a name ButtonCloseListener listener = new ButtonCloseListener(); closeButton.addActionListener(listener); • Here we have a non anonymous inner class class ButtonCloseListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } • The button listener is defined here.
  • 27. Derived Class • We create a MyButton class, that implements the action listener MyButton closeButton = new MyButton("Close"); • Now create the MyButton custom class class MyButton extends JButton implements ActionListener { • The MyButton class is extended from the JButton class and implements the ActionListener interface • This way, the event handling is managed within the MyButton class. addActionListener(this); • Here we add the action listener to the MyButton class.
  • 28. Adapter Classes • Time consuming to define all interface methods • WindowListener has seven methods • What if we only want to use one? • Required to define all methods in interface • Adapter class implements an interface • Does anyone recognize a design pattern here? • Default implementation ({ }, empty body) for all methods
  • 29. Adapter Classes (contd) • You then extend adapter class, • overriding methods for events you care about, such as windowClosing. • Has "is a" relationship with interface • WindowAdapter is a WindowListener • MouseAdapter is a MouseListener