SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie Swing and Graphical User Interface in Java

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 

Kürzlich hochgeladen (20)

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 

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