SlideShare a Scribd company logo
Creating Graphical User Interface
(GUI & Swing, Part 1)
References:
(1)Textbook, chapter 10, 11
(2)Java-Tutorials/tutorial-2015/uiswing/index.html
Java GUI and the swing package
Why should we study this lecture?
Do you want to create GUI applications (graphic
user interface)?
How do GUI applications execute?
What do Java APIs support for developing GUI
App?
2
Objectives
Review
Knowledge used in this lecture:
Event: Some thing happens.
Event in applications: In almost cases, when IO
devices complete a task, an event is thrown  When
user presses a key or clicks mouse, events are
thrown.
Event handler: Code executes when the appropriate
event is thrown.
How does application know an event?
When an IO device completes a task, a signal (called
as interrupt) from the device will be sent to CPU and
operating system (OS) knows it. OS collects states of
keyboard, mouse position, mouse keys,…, called as
event object then OS passes the event object to the
application.
3
Contents
Two Kinds of Applications
Java Model for Event Management
About Java Foundation Classes (JFC)
A Strategy for Designing the GUI
Using Ordinary Swing Components
A Demonstration
4
1- Two Kinds of Apps
Console App.
Compute-centric Apps
Event-based App.
User-centric Apps(GUI)
Model-View Controller Architecture for GUI component.
Model: Object contains data.
View: Object users can see it on the screen
Controller: Object manages events
[www.songho.ca]5
2-Java model for event
management
Delegates
View
Register Table
Update
GUI
6
Component C1 Specific Event Object E1
- Component
- Keyboard state
- Mouse state
Listener L1
Event handler 1
Event handler 2
Model
-data
-Reference to
listener object Run time Environment (JVM)
Event Component Listener code
E1 C1 L1 1234
E2 C2 L2 5678
……..
Application
(from OS)
Controller
Some Common Events
Object Event Interface Method
JButton ActionEvent ActionListener actionPerformed()
JCheckBox ActionEvent
ItemEvent
ActionListener
ItemListener
actionPerformed()
itemStateChanged()
JRadioButton ActionEvent
ItemEvent
ActionListener
ItemListener
actionPerformed()
itemStateChanged()
JTextField
JTextArea
ActionEvent
FocusEvent
ActionListener
FocusListener
actionPerformed()
focusGained(), focusLost()
JPasswordField ActionEvent ActionListener actionPerformed()
7
More Details about events will be introduced in the next session.
3- About Java Foundation Classes
8
 JFC encompass a group of features for building graphical user
interfaces (GUIs) and adding rich graphics functionality and interactivity
to Java applications. It is defined as containing the features shown in the
table below:
This trail concentrates on the Swing components. We help you choose the appropriate components for your GUI, tell you how to use them, and give you the background
Feature Description
Swing GUI
Components
Includes everything from buttons to split panes to tables. Many components are capable of sorting,
printing, and drag and drop, to name a few of the supported features.
Pluggable Look-
and-Feel Support
Allowing a choice of look and feel. For example, the same program can use either the Java or the
Windows look and feel. Additionally, the Java platform supports the GTK+ look and feel, which
makes hundreds of existing look and feels available to Swing programs. Many more look-and-feel
packages are available from various sources.
Accessibility API Enables assistive technologies, such as screen readers and Braille displays, to get information from
the user interface.
Java 2D API Enables developers to easily incorporate high-quality 2D graphics, text, and images in applications
and applets. Java 2D includes extensive APIs for generating and sending high-quality output to
printing devices.
Internationalization Allows developers to build applications that can interact with users worldwide in their own
languages and cultural conventions. With the input method framework developers can build
applications that accept text in languages that use thousands of different characters, such as
Japanese, Chinese, or Korean.
JFC…
9
 Which Swing Packages Should I Use?
The Swing API is powerful, flexible — and immense. The Swing API has 18
public packages:
This trail concentrates on the Swing components. We help you choose the appropriate components for your GUI, tell you how to use them, and give you the background
4- A Strategy for Designing the GUI
Identify needed components.
Isolate regions and behaviors.
Sketch (phác hoạ) the GUI.
Choose Layout managers.
Requirements
Input data
Output Data
Operations
Implement
event handlers
10
5- Ordinary Swing Component
11
Component Properties:
Name, size, location,
background color,
foreground color, font,
enable, editable
Set/get
Ordinary Swing Components
javax.swing package contains APIs for developing
GUI Apps Refer to Java documentation for more
details of this package.
Almost component class names begin with ‘J’
Three categories:
Container components
Ordinary components:
Menu components.
12
Ordinary Swing Components…
Containers: JFrame, JPanel
They contain other components.
They use layout managers to
determine the size and position of
their child components.
JFrame is a top-level container.
JPanel is called general-purpose
container. It is a lightweight container.
13
Ordinary Components
JLabel
JTextfield
JRadioButton
(ButtonGroup)
JComboBox
JTextArea
JScrollBar
JCheckBox
JButton
14
Demo 1
15
Objectives
Use a panel to group some components
Hide and show those as a whole through this panel
Disable the exit button on the frame
The exit button allows user close the application
GUI:
Demo 1
16
Design
Demo 1
17
Class Object name Properties
JFrame GUI_01 Layout: null, defaultCloseOperation: DO_NOTHING
Title: GUI-Demo 1
JPanel pEmp Layout: null, Border: tittleBorder
JLabel lbCode Opaque: true, background: green, foreground: white
horizontalAlignment: RIGHT, text: Code
JLabel others Text: Name, Sex, Degree
ButtonGroup bgrpSex
JRadioButton rdMale buttonGroup: bgrpSex, Text: Male, Selected: true,
JRadioButton rdFemale buttonGroup: bgrpSex, Text: Female, Selected: false
JComboBox cbDegree Model:Ph. D., Master, Engineer, Bachelor, Technician
Setup Properties
Demo 1
18
Code:Constructor
Code for handling the event on the button Exit
Code for handling the event on the button ShowHide
Demo 1
19
View code at the end of the source file, inserted
by NetBeans  Comment
View the contents of the method
initComponents(), inserted by NetBeans, to
explore anonymous classes, then verify them
using Window Explorer
Summary
Two Kinds of Applications
Java Model for Event Management
About Java Foundation Classes (JFC)
A Strategy for Designing the GUI
Using Basic Swing Components
20

More Related Content

What's hot

android-tutorial-for-beginner
android-tutorial-for-beginnerandroid-tutorial-for-beginner
android-tutorial-for-beginnerAjailal Parackal
 
Sikuli
SikuliSikuli
Unit2
Unit2Unit2
Android components
Android componentsAndroid components
Android components
NAVEENA ESWARAN
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a NutshellAleix Solé
 
Android In A Nutshell
Android In A NutshellAndroid In A Nutshell
Android In A Nutshell
Ted Chien
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile Applications11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile Applications
AEGIS-ACCESSIBLE Projects
 
Android Basics
Android BasicsAndroid Basics
Android Basics
Arvind Sahu
 
Android Applications Development
Android Applications DevelopmentAndroid Applications Development
Android Applications Development
Michael Angelo Rivera
 
GDG School Android Workshop
GDG School Android WorkshopGDG School Android Workshop
GDG School Android Workshop
Abderraouf GATTAL
 
Android architecture
Android architecture Android architecture
Android architecture
Trong-An Bui
 
Android programming basics
Android programming basicsAndroid programming basics
Android programming basics
Egerton University
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from Scratch
Taufan Erfiyanto
 
Android session 2
Android session 2Android session 2
Android session 2
Ahesanali Suthar
 
Android basic principles
Android basic principlesAndroid basic principles
Android basic principlesHenk Laracker
 

What's hot (20)

GUI JAVA PROG ~hmftj
GUI  JAVA PROG ~hmftjGUI  JAVA PROG ~hmftj
GUI JAVA PROG ~hmftj
 
android-tutorial-for-beginner
android-tutorial-for-beginnerandroid-tutorial-for-beginner
android-tutorial-for-beginner
 
Sikuli
SikuliSikuli
Sikuli
 
Unit2
Unit2Unit2
Unit2
 
Google Android
Google AndroidGoogle Android
Google Android
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Android components
Android componentsAndroid components
Android components
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a Nutshell
 
Android In A Nutshell
Android In A NutshellAndroid In A Nutshell
Android In A Nutshell
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile Applications11 Java User Interface Libraries for Developing Mobile Applications
11 Java User Interface Libraries for Developing Mobile Applications
 
Android Basics
Android BasicsAndroid Basics
Android Basics
 
Android Applications Development
Android Applications DevelopmentAndroid Applications Development
Android Applications Development
 
GDG School Android Workshop
GDG School Android WorkshopGDG School Android Workshop
GDG School Android Workshop
 
Android architecture
Android architecture Android architecture
Android architecture
 
Android programming basics
Android programming basicsAndroid programming basics
Android programming basics
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from Scratch
 
Android session 2
Android session 2Android session 2
Android session 2
 
Android basic principles
Android basic principlesAndroid basic principles
Android basic principles
 

Similar to Slot04 creating gui

GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.ppt
TabassumMaktum
 
GUI_part_1.pptx
GUI_part_1.pptxGUI_part_1.pptx
GUI_part_1.pptx
Parasuraman43
 
Programming 2: Java Midterm Week Twelve.
Programming 2: Java Midterm Week Twelve.Programming 2: Java Midterm Week Twelve.
Programming 2: Java Midterm Week Twelve.
HyunJeiThaddeus
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System Requirements
Laura Arrigo
 
Windows Programming with Swing
Windows Programming with SwingWindows Programming with Swing
Windows Programming with Swingbackdoor
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
SURBHI SAROHA
 
Chapter 1-Note.docx
Chapter 1-Note.docxChapter 1-Note.docx
Chapter 1-Note.docx
TigistTilahun1
 
Tycs advance java sem 5 unit 1,2,3,4 (2017)
Tycs advance java sem 5 unit 1,2,3,4 (2017)Tycs advance java sem 5 unit 1,2,3,4 (2017)
Tycs advance java sem 5 unit 1,2,3,4 (2017)
WE-IT TUTORIALS
 
Applications use in Java GUIThe Java GUI consists of a separate, .pdf
Applications use in Java GUIThe Java GUI consists of a separate, .pdfApplications use in Java GUIThe Java GUI consists of a separate, .pdf
Applications use in Java GUIThe Java GUI consists of a separate, .pdf
akshay1213
 
Swing components
Swing components Swing components
Swing components
Sameenafathima4
 
java swing programming
java swing programming java swing programming
java swing programming
Ankit Desai
 
The Use of Java Swing’s Components to Develop a Widget
The Use of Java Swing’s Components to Develop a WidgetThe Use of Java Swing’s Components to Develop a Widget
The Use of Java Swing’s Components to Develop a Widget
Waqas Tariq
 
Java swing 1
Java swing 1Java swing 1
Java swing 1
Mukesh Tekwani
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
Liz Sims
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
Mikkel Flindt Heisterberg
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
AbuSufyan82
 
Swing is not dead
Swing is not deadSwing is not dead
Swing is not dead
Piotr Dziewonski
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
guest213e237
 

Similar to Slot04 creating gui (20)

GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.ppt
 
GUI_part_1.pptx
GUI_part_1.pptxGUI_part_1.pptx
GUI_part_1.pptx
 
Programming 2: Java Midterm Week Twelve.
Programming 2: Java Midterm Week Twelve.Programming 2: Java Midterm Week Twelve.
Programming 2: Java Midterm Week Twelve.
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System Requirements
 
Windows Programming with Swing
Windows Programming with SwingWindows Programming with Swing
Windows Programming with Swing
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
Chapter 1-Note.docx
Chapter 1-Note.docxChapter 1-Note.docx
Chapter 1-Note.docx
 
Tycs advance java sem 5 unit 1,2,3,4 (2017)
Tycs advance java sem 5 unit 1,2,3,4 (2017)Tycs advance java sem 5 unit 1,2,3,4 (2017)
Tycs advance java sem 5 unit 1,2,3,4 (2017)
 
Report swings
Report swingsReport swings
Report swings
 
Applications use in Java GUIThe Java GUI consists of a separate, .pdf
Applications use in Java GUIThe Java GUI consists of a separate, .pdfApplications use in Java GUIThe Java GUI consists of a separate, .pdf
Applications use in Java GUIThe Java GUI consists of a separate, .pdf
 
Gu iintro(java)
Gu iintro(java)Gu iintro(java)
Gu iintro(java)
 
Swing components
Swing components Swing components
Swing components
 
java swing programming
java swing programming java swing programming
java swing programming
 
The Use of Java Swing’s Components to Develop a Widget
The Use of Java Swing’s Components to Develop a WidgetThe Use of Java Swing’s Components to Develop a Widget
The Use of Java Swing’s Components to Develop a Widget
 
Java swing 1
Java swing 1Java swing 1
Java swing 1
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
 
Swing is not dead
Swing is not deadSwing is not dead
Swing is not dead
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

Slot04 creating gui

  • 1. Creating Graphical User Interface (GUI & Swing, Part 1) References: (1)Textbook, chapter 10, 11 (2)Java-Tutorials/tutorial-2015/uiswing/index.html Java GUI and the swing package
  • 2. Why should we study this lecture? Do you want to create GUI applications (graphic user interface)? How do GUI applications execute? What do Java APIs support for developing GUI App? 2 Objectives
  • 3. Review Knowledge used in this lecture: Event: Some thing happens. Event in applications: In almost cases, when IO devices complete a task, an event is thrown  When user presses a key or clicks mouse, events are thrown. Event handler: Code executes when the appropriate event is thrown. How does application know an event? When an IO device completes a task, a signal (called as interrupt) from the device will be sent to CPU and operating system (OS) knows it. OS collects states of keyboard, mouse position, mouse keys,…, called as event object then OS passes the event object to the application. 3
  • 4. Contents Two Kinds of Applications Java Model for Event Management About Java Foundation Classes (JFC) A Strategy for Designing the GUI Using Ordinary Swing Components A Demonstration 4
  • 5. 1- Two Kinds of Apps Console App. Compute-centric Apps Event-based App. User-centric Apps(GUI) Model-View Controller Architecture for GUI component. Model: Object contains data. View: Object users can see it on the screen Controller: Object manages events [www.songho.ca]5
  • 6. 2-Java model for event management Delegates View Register Table Update GUI 6 Component C1 Specific Event Object E1 - Component - Keyboard state - Mouse state Listener L1 Event handler 1 Event handler 2 Model -data -Reference to listener object Run time Environment (JVM) Event Component Listener code E1 C1 L1 1234 E2 C2 L2 5678 …….. Application (from OS) Controller
  • 7. Some Common Events Object Event Interface Method JButton ActionEvent ActionListener actionPerformed() JCheckBox ActionEvent ItemEvent ActionListener ItemListener actionPerformed() itemStateChanged() JRadioButton ActionEvent ItemEvent ActionListener ItemListener actionPerformed() itemStateChanged() JTextField JTextArea ActionEvent FocusEvent ActionListener FocusListener actionPerformed() focusGained(), focusLost() JPasswordField ActionEvent ActionListener actionPerformed() 7 More Details about events will be introduced in the next session.
  • 8. 3- About Java Foundation Classes 8  JFC encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications. It is defined as containing the features shown in the table below: This trail concentrates on the Swing components. We help you choose the appropriate components for your GUI, tell you how to use them, and give you the background Feature Description Swing GUI Components Includes everything from buttons to split panes to tables. Many components are capable of sorting, printing, and drag and drop, to name a few of the supported features. Pluggable Look- and-Feel Support Allowing a choice of look and feel. For example, the same program can use either the Java or the Windows look and feel. Additionally, the Java platform supports the GTK+ look and feel, which makes hundreds of existing look and feels available to Swing programs. Many more look-and-feel packages are available from various sources. Accessibility API Enables assistive technologies, such as screen readers and Braille displays, to get information from the user interface. Java 2D API Enables developers to easily incorporate high-quality 2D graphics, text, and images in applications and applets. Java 2D includes extensive APIs for generating and sending high-quality output to printing devices. Internationalization Allows developers to build applications that can interact with users worldwide in their own languages and cultural conventions. With the input method framework developers can build applications that accept text in languages that use thousands of different characters, such as Japanese, Chinese, or Korean.
  • 9. JFC… 9  Which Swing Packages Should I Use? The Swing API is powerful, flexible — and immense. The Swing API has 18 public packages: This trail concentrates on the Swing components. We help you choose the appropriate components for your GUI, tell you how to use them, and give you the background
  • 10. 4- A Strategy for Designing the GUI Identify needed components. Isolate regions and behaviors. Sketch (phác hoạ) the GUI. Choose Layout managers. Requirements Input data Output Data Operations Implement event handlers 10
  • 11. 5- Ordinary Swing Component 11 Component Properties: Name, size, location, background color, foreground color, font, enable, editable Set/get
  • 12. Ordinary Swing Components javax.swing package contains APIs for developing GUI Apps Refer to Java documentation for more details of this package. Almost component class names begin with ‘J’ Three categories: Container components Ordinary components: Menu components. 12
  • 13. Ordinary Swing Components… Containers: JFrame, JPanel They contain other components. They use layout managers to determine the size and position of their child components. JFrame is a top-level container. JPanel is called general-purpose container. It is a lightweight container. 13
  • 15. Demo 1 15 Objectives Use a panel to group some components Hide and show those as a whole through this panel Disable the exit button on the frame The exit button allows user close the application GUI:
  • 17. Demo 1 17 Class Object name Properties JFrame GUI_01 Layout: null, defaultCloseOperation: DO_NOTHING Title: GUI-Demo 1 JPanel pEmp Layout: null, Border: tittleBorder JLabel lbCode Opaque: true, background: green, foreground: white horizontalAlignment: RIGHT, text: Code JLabel others Text: Name, Sex, Degree ButtonGroup bgrpSex JRadioButton rdMale buttonGroup: bgrpSex, Text: Male, Selected: true, JRadioButton rdFemale buttonGroup: bgrpSex, Text: Female, Selected: false JComboBox cbDegree Model:Ph. D., Master, Engineer, Bachelor, Technician Setup Properties
  • 18. Demo 1 18 Code:Constructor Code for handling the event on the button Exit Code for handling the event on the button ShowHide
  • 19. Demo 1 19 View code at the end of the source file, inserted by NetBeans  Comment View the contents of the method initComponents(), inserted by NetBeans, to explore anonymous classes, then verify them using Window Explorer
  • 20. Summary Two Kinds of Applications Java Model for Event Management About Java Foundation Classes (JFC) A Strategy for Designing the GUI Using Basic Swing Components 20