SlideShare una empresa de Scribd logo
1 de 29
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

Más contenido relacionado

La actualidad más candente (20)

java swing
java swingjava swing
java swing
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Swing
SwingSwing
Swing
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Chapter 1 swings
Chapter 1 swingsChapter 1 swings
Chapter 1 swings
 
Swings
SwingsSwings
Swings
 
Java swing
Java swingJava swing
Java swing
 
Java swing
Java swingJava swing
Java swing
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
Gui in java
Gui in javaGui in java
Gui in java
 
Complete java swing
Complete java swingComplete java swing
Complete java swing
 
Java swing
Java swingJava swing
Java swing
 
28 awt
28 awt28 awt
28 awt
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
Jdbc
JdbcJdbc
Jdbc
 
Swings in java
Swings in javaSwings in java
Swings in java
 
Awt
AwtAwt
Awt
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Java
 

Destacado

Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface Bivek Pakuwal
 
Java Swing
Java SwingJava Swing
Java SwingShraddha
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART IOXUS 20
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART IIIOXUS 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 Designfrancopw
 
USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTvicci4041
 
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ériencelouschwartz
 
Oracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensembleOracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensembleANASYS
 
MC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUAMC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUASajid 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 transferAnkit Desai
 
Explorations in Creative Coding
Explorations in Creative CodingExplorations in Creative Coding
Explorations in Creative CodingEelco 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) - InheritanceOUM SAOKOSAL
 
User Interface Design @iRajLal
User Interface Design @iRajLalUser Interface Design @iRajLal
User Interface Design @iRajLalRaj Lal
 

Destacado (18)

Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
 
Java Swing
Java SwingJava Swing
Java Swing
 
Graphical User Interface
Graphical User InterfaceGraphical User Interface
Graphical User Interface
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
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
 
java swing
java swingjava swing
java swing
 
USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPT
 
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
 
Oracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensembleOracle ADF : Vue d'ensemble
Oracle ADF : Vue d'ensemble
 
MC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUAMC140400444_Final Project Presentation_GUA
MC140400444_Final Project Presentation_GUA
 
Java swings
Java swingsJava swings
Java swings
 
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
 
Explorations in Creative Coding
Explorations in Creative CodingExplorations in Creative Coding
Explorations in Creative Coding
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
java swing programming
java swing programming java swing programming
java swing programming
 
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
 
User Interface Design @iRajLal
User Interface Design @iRajLalUser Interface Design @iRajLal
User Interface Design @iRajLal
 

Similar a Swing and Graphical User Interface in Java

Similar a 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
 
Events1
Events1Events1
Events1
 
EventHandling.pptx
EventHandling.pptxEventHandling.pptx
EventHandling.pptx
 
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
 
Android - Activity, Services
Android - Activity, ServicesAndroid - Activity, Services
Android - Activity, Services
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
 
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
 
Awt event
Awt eventAwt event
Awt event
 
14a-gui.ppt
14a-gui.ppt14a-gui.ppt
14a-gui.ppt
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
03_GUI.ppt
03_GUI.ppt03_GUI.ppt
03_GUI.ppt
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
09events
09events09events
09events
 
FlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.pptFlutterArchitecture FlutterArchitecture.ppt
FlutterArchitecture FlutterArchitecture.ppt
 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design
 
Module3.11.pptx
Module3.11.pptxModule3.11.pptx
Module3.11.pptx
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
CS3391 -OOP -UNIT – V NOTES FINAL.pdf
CS3391 -OOP -UNIT – V NOTES FINAL.pdfCS3391 -OOP -UNIT – V NOTES FINAL.pdf
CS3391 -OOP -UNIT – V NOTES FINAL.pdf
 
28-GUI application.pptx.pdf
28-GUI application.pptx.pdf28-GUI application.pptx.pdf
28-GUI application.pptx.pdf
 

Más de 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 Socketsbabak danyal
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streamsbabak danyal
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the desbabak danyal
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network securitybabak danyal
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systemsbabak danyal
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systemsbabak danyal
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systemsbabak danyal
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systemsbabak danyal
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systemsbabak danyal
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systemsbabak danyal
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systemsbabak danyal
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systemsbabak danyal
 
Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signababak danyal
 
Lecture9 Signal and Systems
Lecture9 Signal and SystemsLecture9 Signal and Systems
Lecture9 Signal and Systemsbabak danyal
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniquesbabak danyal
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Securitybabak danyal
 
Problems at independence
Problems at independenceProblems at independence
Problems at independencebabak danyal
 

Más de babak danyal (20)

applist
applistapplist
applist
 
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
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Tcp sockets
Tcp socketsTcp sockets
Tcp sockets
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the des
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network security
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systems
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systems
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systems
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systems
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systems
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systems
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systems
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systems
 
Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signa
 
Lecture9 Signal and Systems
Lecture9 Signal and SystemsLecture9 Signal and Systems
Lecture9 Signal and Systems
 
Lecture9
Lecture9Lecture9
Lecture9
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniques
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Security
 
Problems at independence
Problems at independenceProblems at independence
Problems at independence
 

Último

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 

Último (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 

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