SlideShare a Scribd company logo
Programming Logic and Design
Eighth Edition
Chapter 12
Event-Driven GUI Programming,
Multithreading, and Animation
Objectives
2
In this chapter, you will learn about:
• The principles of event-driven programming
• User-initiated actions and GUI components
• Designing graphical user interfaces
• Developing an event-driven application
• Threads and multithreading
• Creating animation
Programming Logic and Design, Eighth Edition
Understanding Event-Driven
Programming
3
• Operating system
– The software used to run a computer and manage its
resources
• Early days of computing
– Command line entry: the DOS prompt
– Interacting with a computer operating system was
difficult
– The user had to know the exact syntax to use when
typing commands
Programming Logic and Design, Eighth Edition
Understanding Event-Driven
Programming (continued)
4
Figure 12-1 Command prompt screen
Programming Logic and Design, Eighth Edition
5
• Modern operating system software
– Allows use of mouse or other pointing device to select
icons
– GUI
• Computer users can expect to see a standard
interface
• Event
– Generates a message sent to an object
Understanding Event-Driven
Programming (continued)
Programming Logic and Design, Eighth Edition
6
Understanding
Event-Driven
Programming
(continued)
Figure 12-2 A GUI application that
contains buttons and icons
Programming Logic and Design, Eighth Edition
7
Understanding Event-Driven
Programming (continued)
• Event-driven or event-based program
– Actions occur in response to user-initiated events such as
clicking a mouse button
– Emphasis is on the objects that the user can manipulate
– Programmer writes instructions within modules that
execute each type of event
Programming Logic and Design, Eighth Edition
8
Understanding Event-Driven
Programming (continued)
• Procedural application
– Programmer controls order of program statements
• Event-driven programs
– User might initiate any number of events in any order
– More flexible than procedural counterparts
Programming Logic and Design, Eighth Edition
9
Understanding Event-Driven
Programming (continued)
• Source of the event
– The component from which an event is generated
• Listener
– An object that is “interested in” an event to which you
want it to respond to
• Not all objects can receive all events
• Event-driven programming is relatively new
– But it uses many similar techniques to procedural
Programming Logic and Design, Eighth Edition
User-Initiated Actions and GUI
Components
10
Table 12-1 Common user-initiated events
Programming Logic and Design, Eighth Edition
User-Initiated Actions and GUI
Components (continued)
11
Table 12-2 Common GUI components
Programming Logic and Design, Eighth Edition
User-Initiated Actions and GUI
Components (continued)
12
Figure 12-3 Common GUI components
Programming Logic and Design, Eighth Edition
13
User-Initiated Actions and GUI
Components (continued)
• Do not create the GUI components you need from
scratch
– Call prewritten methods that draw the GUI components
on the screen for you
• Components themselves are constructed using
existing classes complete with names, attributes,
and methods
• Text or graphical environment
Programming Logic and Design, Eighth Edition
User-Initiated Actions and GUI
Components (continued)
14
Figure 12-4 Button class
Programming Logic and Design, Eighth Edition
User-Initiated Actions and GUI
Components (continued)
15
• Create a Button object
– Button myProgramButton
• Use Button’s methods
– myProgramButton.setText("Click here")
– myProgramButton.setPosition(10, 30)
• Different GUI classes support different attributes
and methods
Programming Logic and Design, Eighth Edition
Designing Graphical User Interfaces
16
• The interface should be natural and predictable
• The interface should be attractive, easy to read, and
nondistracting
• To some extent, it’s helpful if the user can customize
your applications
• The program should be forgiving
• The GUI is only a means to an end
Programming Logic and Design, Eighth Edition
The Interface Should Be Natural
and Predictable
17
• Represent objects like their real-world counterparts
• Actions should be predictable
– Similar to other programs
• Be predictable in layout
– Put related items together in proper order
– Locate menu at top, etc.
Programming Logic and Design, Eighth Edition
The Interface Should Be Attractive,
Easy to Read, and Nondistracting
18
• Attractive
– People are more likely to use it
• Easy to read
– Less likely to make mistakes
• Screen designs should not be distracting
– Fancy fonts and weird color combinations are the signs of
amateur designers
Programming Logic and Design, Eighth Edition
To Some Extent, It’s Helpful If the User
Can Customize Your Applications
19
• It’s helpful if users can position the components in
the order with which it’s easiest for them to work
• Users appreciate being able to change features like
color schemes
• Accessibility
– Screen design issues that make programs easier to use for
people with physical limitations
Programming Logic and Design, Eighth Edition
The Program Should Be Forgiving
20
• Always provide an escape route
– Accommodate users who make bad choices or change
their minds
– Back button or functional Escape key
– Allow users to perform tasks in a variety of ways:
• Mouse click
• Keyboard shortcut
• Menu item
• Disability options
Programming Logic and Design, Eighth Edition
The GUI Is Only a Means to an End
21
• The GUI is only an interface
• The point of a graphical interface is to help people
be more productive
• The real work of any GUI program is done after the
user clicks a button or makes a list box selection
Programming Logic and Design, Eighth Edition
Developing an Event-Driven
Application
22
• Steps to developing a computer program
1. Understanding the problem
2. Planning the logic
2a. Creating storyboards
2b. Defining the objects
2c. Defining the connections between the screens the user will see
3. Coding the program
4. Translating the program into machine language
5. Testing the program
6. Putting the program into production
7. Maintaining the program
Programming Logic and Design, Eighth Edition
Developing an
Event-Driven Application (continued)
23
Table 12-3 Insurance premiums based on customer characteristics
Programming Logic and Design, Eighth Edition
Creating Wireframes
24
• Wireframe
– A picture or sketch of a screen the user will see when
running a program
– Also called a page schematic or screen blueprint
– Can be pencil sketches or produced by software
applications
Programming Logic and Design, Eighth Edition
Creating Storyboards
25
• Storyboard
– Contains a series of wireframes that represent a user’s
experience with the proposed software
• GUI storyboards
– Represent “snapshot” views of the screens the user will
encounter during the run of a program
Programming Logic and Design, Eighth Edition
Creating Storyboards (continued)
26
Figure 12-5 Storyboard for insurance program
Programming Logic and Design, Eighth Edition
27
Defining the Storyboard Objects
in an Object Dictionary
• An event-driven program may contain dozens or
even hundreds of objects
• Object dictionary
– A list of the objects used in a program
– Includes which screens they are used on and whether any
code, or script, is associated with them
Programming Logic and Design, Eighth Edition
28
Defining the Storyboard Objects
in an Object Dictionary (continued)
Figure 12-6 Object dictionary for insurance premium program
Programming Logic and Design, Eighth Edition
29
Defining Connections Between
the User Screens
• Draw the connections between the screens to show
how they interact
• Interactivity diagram
– Shows the relationship between screens in an interactive
GUI program
• One screen may lead to different screens depending
on the options the user selects at any one screen
Programming Logic and Design, Eighth Edition
30
Defining Connections Between
the User Screens (continued)
Figure 12-7 Interactivity diagram for insurance
premium program
Figure 12-8 Interactivity diagram for a
complicated program
Programming Logic and Design, Eighth Edition
31
Planning the Logic
• Design the screens
• Define the objects
• Define how the screens will connect
• Then start to plan the class
• Create the component onto which all the GUI
elements are placed
– Might use a class with a name such as Screen, Form, or
Window
Programming Logic and Design, Eighth Edition
32
Figure 12-9 Component definitions for first screen of insurance program
Programming Logic and Design, Eighth Edition
Planning the
Logic (continued)
33
• Register components
– Sign them up so that they can react to events initiated by
other components
• Container
– A class of objects whose main purpose is to hold other
elements
– Contains methods that allow you to set physical
properties such as height and width
– Contains methods that allow you to add the appropriate
components to a container
Planning the Logic (continued)
Programming Logic and Design, Eighth Edition
34
Figure 12-10 Statements that create
screen1
Figure 12-11 Statements that define and
create screen2 and its components
Planning the Logic (continued)
Programming Logic and Design, Eighth Edition
35
Figure 12-12 Pseudocode for calcRoutine()
method of insurance premium programProgramming Logic and Design, Eighth Edition
Planning the Logic (continued)
36
Understanding Threads and
Multithreading
• Thread
– The flow of execution of one set of program statements
• Many applications follow a single thread
• A computer’s central processing unit (CPU) can
execute only one statement at a time regardless of
its processor speed
• A computer with multiple CPUs can execute
multiple instructions simultaneously
Programming Logic and Design, Eighth Edition
37
Understanding Threads and
Multithreading (continued)
• Multithreading
– Using multiple threads of execution
– Multiple threads share the CPU’s time for a single
processor
• Use multithreading to improve the performance of
your programs
– More user friendly
• Object-oriented languages often contain a built-in
Thread class
– Contains methods to help handle multiple threads
Programming Logic and Design, Eighth Edition
38
Figure 12-14 Executing multiple tasks
as single threads in a single-processor
system
Figure 12-15 Executing multiple threads in
a single-processor system
Understanding Threads and
Multithreading (continued)
Programming Logic and Design, Eighth Edition
39
• Code carefully to avoid deadlock and starvation
– Two or more threads wait for each other
– Threads are abandoned when other threads have all
resources
• Techniques like thread synchronization avoid
problems such as:
– Two clerks accessing the same record, and the first one
updating it while the other is still viewing it
– The second user still thinks the data is accurate
Understanding Threads and
Multithreading (continued)
Programming Logic and Design, Eighth Edition
40
Creating Animation
• Animation
– A rapid sequence of still images
– Each is slightly different from the previous one
– Produces the illusion of movement
• Object-oriented languages offer built-in classes
used to draw geometric figures on the screen
• Position
– Horizontal: x-axis, x-coordinate
– Vertical: y-axis, y-coordinate
Programming Logic and Design, Eighth Edition
Creating Animation (continued)
41
Figure 12-16 Selected screen coordinate positions
Programming Logic and Design, Eighth Edition
Creating Animation (continued)
42
• MovingCircle
class
– Moves a circle across
the screen
– Constants SIZE and
INCREASE
– drawCircle()
method
– sleep() method
Figure 12-17 The MovingCircle class
Programming Logic and Design, Eighth Edition
43
Figure 12-18 Output
of the
MovingCircle
application
Creating Animation (continued)
Programming Logic and Design, Eighth Edition
Summary
44
• Graphical user interface (GUI)
– Users manipulate objects such as buttons and menus
– Listeners are “interested in” an event
– Common user events involve mouse events
• Common GUI components include labels, text
boxes, buttons, check boxes, check box groups,
option buttons, and list boxes
• Interface should be natural, predictable, attractive,
easy to read, and nondistracting
Programming Logic and Design, Eighth Edition
Summary (continued)
45
• Event-driven applications require wireframes and
storyboards, defining objects and defining
connections the user will see
• Thread
– The flow of execution of one set of program statements
• Animation
– A rapid sequence of still images
Programming Logic and Design, Eighth Edition
Ad

More Related Content

What's hot (20)

Software quality
Software qualitySoftware quality
Software quality
Sara Mehmood
 
Spm unit 4
Spm unit 4Spm unit 4
Spm unit 4
sweetyammu
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
Jothi Lakshmi
 
Address in the target code in Compiler Construction
Address in the target code in Compiler ConstructionAddress in the target code in Compiler Construction
Address in the target code in Compiler Construction
Muhammad Haroon
 
Stepwise planning
Stepwise planningStepwise planning
Stepwise planning
KavithaGowri
 
CoAP - Web Protocol for IoT
CoAP - Web Protocol for IoTCoAP - Web Protocol for IoT
CoAP - Web Protocol for IoT
Aniruddha Chakrabarti
 
CORBA
CORBACORBA
CORBA
Mokshada Nayak
 
Function Point Analysis (FPA) by Dr. B. J. Mohite
Function Point Analysis (FPA) by Dr. B. J. MohiteFunction Point Analysis (FPA) by Dr. B. J. Mohite
Function Point Analysis (FPA) by Dr. B. J. Mohite
Zeal Education Society, Pune
 
Unit 1.2 Stepwise Project Planning.pdf
Unit 1.2 Stepwise Project Planning.pdfUnit 1.2 Stepwise Project Planning.pdf
Unit 1.2 Stepwise Project Planning.pdf
AkshayDwivedi31
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)
Archana432045
 
Loops in flow
Loops in flowLoops in flow
Loops in flow
indhu mathi
 
MG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENTMG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENT
Kathirvel Ayyaswamy
 
Software requirement specification
Software requirement specificationSoftware requirement specification
Software requirement specification
shiprashakya2
 
Lect4 software economics
Lect4 software economicsLect4 software economics
Lect4 software economics
meena466141
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERING
Saqib Raza
 
IOT Reference Model.doc
IOT Reference Model.docIOT Reference Model.doc
IOT Reference Model.doc
venui2
 
6LoWPAN: An open IoT Networking Protocol
6LoWPAN: An open IoT Networking Protocol6LoWPAN: An open IoT Networking Protocol
6LoWPAN: An open IoT Networking Protocol
Samsung Open Source Group
 
6lowpan introduction
6lowpan introduction6lowpan introduction
6lowpan introduction
Martin Abraham
 
Distributed objects & components of corba
Distributed objects & components of corbaDistributed objects & components of corba
Distributed objects & components of corba
Mayuresh Wadekar
 
Unit 4
Unit 4Unit 4
Unit 4
Mayura shelke
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
Jothi Lakshmi
 
Address in the target code in Compiler Construction
Address in the target code in Compiler ConstructionAddress in the target code in Compiler Construction
Address in the target code in Compiler Construction
Muhammad Haroon
 
Unit 1.2 Stepwise Project Planning.pdf
Unit 1.2 Stepwise Project Planning.pdfUnit 1.2 Stepwise Project Planning.pdf
Unit 1.2 Stepwise Project Planning.pdf
AkshayDwivedi31
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)
Archana432045
 
MG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENTMG6088 SOFTWARE PROJECT MANAGEMENT
MG6088 SOFTWARE PROJECT MANAGEMENT
Kathirvel Ayyaswamy
 
Software requirement specification
Software requirement specificationSoftware requirement specification
Software requirement specification
shiprashakya2
 
Lect4 software economics
Lect4 software economicsLect4 software economics
Lect4 software economics
meena466141
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERING
Saqib Raza
 
IOT Reference Model.doc
IOT Reference Model.docIOT Reference Model.doc
IOT Reference Model.doc
venui2
 
Distributed objects & components of corba
Distributed objects & components of corbaDistributed objects & components of corba
Distributed objects & components of corba
Mayuresh Wadekar
 

Similar to Chapter 12 Lecture: GUI Programming, Multithreading, and Animation (20)

Unit 2
Unit 2Unit 2
Unit 2
Siddhant Goyal
 
CREATIVE TECHNOLOGY 7 QI-L1
CREATIVE TECHNOLOGY 7 QI-L1CREATIVE TECHNOLOGY 7 QI-L1
CREATIVE TECHNOLOGY 7 QI-L1
FLORENCE FERNNADEZ
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
BernardVelasco1
 
Climberreport
ClimberreportClimberreport
Climberreport
LuckyTolani1
 
chapter12 - Software engineering.pdf
chapter12 - Software engineering.pdfchapter12 - Software engineering.pdf
chapter12 - Software engineering.pdf
satonaka3
 
ITE 101 - Week 5
ITE 101 - Week 5ITE 101 - Week 5
ITE 101 - Week 5
Frank Monaco
 
PT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - AndroidPT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - Android
drjuniornet
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and Design
May Belleza
 
Bouncing ball content management system project report.pdf
Bouncing ball content management system project report.pdfBouncing ball content management system project report.pdf
Bouncing ball content management system project report.pdf
Kamal Acharya
 
Automatic Graphical Design Generator
Automatic Graphical Design GeneratorAutomatic Graphical Design Generator
Automatic Graphical Design Generator
IRJET Journal
 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report
Dileep Maurya
 
Project
ProjectProject
Project
Srijan Bose (Available for immediate joining)
 
GUI_part_1.pptx
GUI_part_1.pptxGUI_part_1.pptx
GUI_part_1.pptx
Parasuraman43
 
Android Infrastructure
Android InfrastructureAndroid Infrastructure
Android Infrastructure
Eyad Almasri
 
EXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNSEXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNS
ROHISIVAM
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
Neha Sharma
 
Visual basic
Visual basicVisual basic
Visual basic
sanjay joshi
 
Computer graphics Applications and System Overview
Computer graphics Applications and System OverviewComputer graphics Applications and System Overview
Computer graphics Applications and System Overview
RAJARATNAS
 
1. ch 1-introduction
1. ch 1-introduction1. ch 1-introduction
1. ch 1-introduction
Delowar hossain
 
Tictactoe game management system project report.pdf
Tictactoe game management system project report.pdfTictactoe game management system project report.pdf
Tictactoe game management system project report.pdf
Kamal Acharya
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
BernardVelasco1
 
chapter12 - Software engineering.pdf
chapter12 - Software engineering.pdfchapter12 - Software engineering.pdf
chapter12 - Software engineering.pdf
satonaka3
 
PT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - AndroidPT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - Android
drjuniornet
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and Design
May Belleza
 
Bouncing ball content management system project report.pdf
Bouncing ball content management system project report.pdfBouncing ball content management system project report.pdf
Bouncing ball content management system project report.pdf
Kamal Acharya
 
Automatic Graphical Design Generator
Automatic Graphical Design GeneratorAutomatic Graphical Design Generator
Automatic Graphical Design Generator
IRJET Journal
 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report
Dileep Maurya
 
Android Infrastructure
Android InfrastructureAndroid Infrastructure
Android Infrastructure
Eyad Almasri
 
EXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNSEXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNS
ROHISIVAM
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
Neha Sharma
 
Computer graphics Applications and System Overview
Computer graphics Applications and System OverviewComputer graphics Applications and System Overview
Computer graphics Applications and System Overview
RAJARATNAS
 
Tictactoe game management system project report.pdf
Tictactoe game management system project report.pdfTictactoe game management system project report.pdf
Tictactoe game management system project report.pdf
Kamal Acharya
 
Ad

More from Nicole Ryan (20)

Testing and Improving Performance
Testing and Improving PerformanceTesting and Improving Performance
Testing and Improving Performance
Nicole Ryan
 
Optimizing a website for search engines
Optimizing a website for search enginesOptimizing a website for search engines
Optimizing a website for search engines
Nicole Ryan
 
Inheritance
InheritanceInheritance
Inheritance
Nicole Ryan
 
Javascript programming using the document object model
Javascript programming using the document object modelJavascript programming using the document object model
Javascript programming using the document object model
Nicole Ryan
 
Working with Video and Audio
Working with Video and AudioWorking with Video and Audio
Working with Video and Audio
Nicole Ryan
 
Working with Images
Working with ImagesWorking with Images
Working with Images
Nicole Ryan
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
Nicole Ryan
 
Creating Visual Effects and Animation
Creating Visual Effects and AnimationCreating Visual Effects and Animation
Creating Visual Effects and Animation
Nicole Ryan
 
Creating and Processing Web Forms
Creating and Processing Web FormsCreating and Processing Web Forms
Creating and Processing Web Forms
Nicole Ryan
 
Organizing Content with Lists and Tables
Organizing Content with Lists and TablesOrganizing Content with Lists and Tables
Organizing Content with Lists and Tables
Nicole Ryan
 
Social media and your website
Social media and your websiteSocial media and your website
Social media and your website
Nicole Ryan
 
Working with Links
Working with LinksWorking with Links
Working with Links
Nicole Ryan
 
Formatting text with CSS
Formatting text with CSSFormatting text with CSS
Formatting text with CSS
Nicole Ryan
 
Laying Out Elements with CSS
Laying Out Elements with CSSLaying Out Elements with CSS
Laying Out Elements with CSS
Nicole Ryan
 
Getting Started with CSS
Getting Started with CSSGetting Started with CSS
Getting Started with CSS
Nicole Ryan
 
Structure Web Content
Structure Web ContentStructure Web Content
Structure Web Content
Nicole Ryan
 
Getting Started with your Website
Getting Started with your WebsiteGetting Started with your Website
Getting Started with your Website
Nicole Ryan
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
Nicole Ryan
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: Modularity
Nicole Ryan
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: Arrays
Nicole Ryan
 
Testing and Improving Performance
Testing and Improving PerformanceTesting and Improving Performance
Testing and Improving Performance
Nicole Ryan
 
Optimizing a website for search engines
Optimizing a website for search enginesOptimizing a website for search engines
Optimizing a website for search engines
Nicole Ryan
 
Javascript programming using the document object model
Javascript programming using the document object modelJavascript programming using the document object model
Javascript programming using the document object model
Nicole Ryan
 
Working with Video and Audio
Working with Video and AudioWorking with Video and Audio
Working with Video and Audio
Nicole Ryan
 
Working with Images
Working with ImagesWorking with Images
Working with Images
Nicole Ryan
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
Nicole Ryan
 
Creating Visual Effects and Animation
Creating Visual Effects and AnimationCreating Visual Effects and Animation
Creating Visual Effects and Animation
Nicole Ryan
 
Creating and Processing Web Forms
Creating and Processing Web FormsCreating and Processing Web Forms
Creating and Processing Web Forms
Nicole Ryan
 
Organizing Content with Lists and Tables
Organizing Content with Lists and TablesOrganizing Content with Lists and Tables
Organizing Content with Lists and Tables
Nicole Ryan
 
Social media and your website
Social media and your websiteSocial media and your website
Social media and your website
Nicole Ryan
 
Working with Links
Working with LinksWorking with Links
Working with Links
Nicole Ryan
 
Formatting text with CSS
Formatting text with CSSFormatting text with CSS
Formatting text with CSS
Nicole Ryan
 
Laying Out Elements with CSS
Laying Out Elements with CSSLaying Out Elements with CSS
Laying Out Elements with CSS
Nicole Ryan
 
Getting Started with CSS
Getting Started with CSSGetting Started with CSS
Getting Started with CSS
Nicole Ryan
 
Structure Web Content
Structure Web ContentStructure Web Content
Structure Web Content
Nicole Ryan
 
Getting Started with your Website
Getting Started with your WebsiteGetting Started with your Website
Getting Started with your Website
Nicole Ryan
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
Nicole Ryan
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: Modularity
Nicole Ryan
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: Arrays
Nicole Ryan
 
Ad

Recently uploaded (20)

03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 

Chapter 12 Lecture: GUI Programming, Multithreading, and Animation

  • 1. Programming Logic and Design Eighth Edition Chapter 12 Event-Driven GUI Programming, Multithreading, and Animation
  • 2. Objectives 2 In this chapter, you will learn about: • The principles of event-driven programming • User-initiated actions and GUI components • Designing graphical user interfaces • Developing an event-driven application • Threads and multithreading • Creating animation Programming Logic and Design, Eighth Edition
  • 3. Understanding Event-Driven Programming 3 • Operating system – The software used to run a computer and manage its resources • Early days of computing – Command line entry: the DOS prompt – Interacting with a computer operating system was difficult – The user had to know the exact syntax to use when typing commands Programming Logic and Design, Eighth Edition
  • 4. Understanding Event-Driven Programming (continued) 4 Figure 12-1 Command prompt screen Programming Logic and Design, Eighth Edition
  • 5. 5 • Modern operating system software – Allows use of mouse or other pointing device to select icons – GUI • Computer users can expect to see a standard interface • Event – Generates a message sent to an object Understanding Event-Driven Programming (continued) Programming Logic and Design, Eighth Edition
  • 6. 6 Understanding Event-Driven Programming (continued) Figure 12-2 A GUI application that contains buttons and icons Programming Logic and Design, Eighth Edition
  • 7. 7 Understanding Event-Driven Programming (continued) • Event-driven or event-based program – Actions occur in response to user-initiated events such as clicking a mouse button – Emphasis is on the objects that the user can manipulate – Programmer writes instructions within modules that execute each type of event Programming Logic and Design, Eighth Edition
  • 8. 8 Understanding Event-Driven Programming (continued) • Procedural application – Programmer controls order of program statements • Event-driven programs – User might initiate any number of events in any order – More flexible than procedural counterparts Programming Logic and Design, Eighth Edition
  • 9. 9 Understanding Event-Driven Programming (continued) • Source of the event – The component from which an event is generated • Listener – An object that is “interested in” an event to which you want it to respond to • Not all objects can receive all events • Event-driven programming is relatively new – But it uses many similar techniques to procedural Programming Logic and Design, Eighth Edition
  • 10. User-Initiated Actions and GUI Components 10 Table 12-1 Common user-initiated events Programming Logic and Design, Eighth Edition
  • 11. User-Initiated Actions and GUI Components (continued) 11 Table 12-2 Common GUI components Programming Logic and Design, Eighth Edition
  • 12. User-Initiated Actions and GUI Components (continued) 12 Figure 12-3 Common GUI components Programming Logic and Design, Eighth Edition
  • 13. 13 User-Initiated Actions and GUI Components (continued) • Do not create the GUI components you need from scratch – Call prewritten methods that draw the GUI components on the screen for you • Components themselves are constructed using existing classes complete with names, attributes, and methods • Text or graphical environment Programming Logic and Design, Eighth Edition
  • 14. User-Initiated Actions and GUI Components (continued) 14 Figure 12-4 Button class Programming Logic and Design, Eighth Edition
  • 15. User-Initiated Actions and GUI Components (continued) 15 • Create a Button object – Button myProgramButton • Use Button’s methods – myProgramButton.setText("Click here") – myProgramButton.setPosition(10, 30) • Different GUI classes support different attributes and methods Programming Logic and Design, Eighth Edition
  • 16. Designing Graphical User Interfaces 16 • The interface should be natural and predictable • The interface should be attractive, easy to read, and nondistracting • To some extent, it’s helpful if the user can customize your applications • The program should be forgiving • The GUI is only a means to an end Programming Logic and Design, Eighth Edition
  • 17. The Interface Should Be Natural and Predictable 17 • Represent objects like their real-world counterparts • Actions should be predictable – Similar to other programs • Be predictable in layout – Put related items together in proper order – Locate menu at top, etc. Programming Logic and Design, Eighth Edition
  • 18. The Interface Should Be Attractive, Easy to Read, and Nondistracting 18 • Attractive – People are more likely to use it • Easy to read – Less likely to make mistakes • Screen designs should not be distracting – Fancy fonts and weird color combinations are the signs of amateur designers Programming Logic and Design, Eighth Edition
  • 19. To Some Extent, It’s Helpful If the User Can Customize Your Applications 19 • It’s helpful if users can position the components in the order with which it’s easiest for them to work • Users appreciate being able to change features like color schemes • Accessibility – Screen design issues that make programs easier to use for people with physical limitations Programming Logic and Design, Eighth Edition
  • 20. The Program Should Be Forgiving 20 • Always provide an escape route – Accommodate users who make bad choices or change their minds – Back button or functional Escape key – Allow users to perform tasks in a variety of ways: • Mouse click • Keyboard shortcut • Menu item • Disability options Programming Logic and Design, Eighth Edition
  • 21. The GUI Is Only a Means to an End 21 • The GUI is only an interface • The point of a graphical interface is to help people be more productive • The real work of any GUI program is done after the user clicks a button or makes a list box selection Programming Logic and Design, Eighth Edition
  • 22. Developing an Event-Driven Application 22 • Steps to developing a computer program 1. Understanding the problem 2. Planning the logic 2a. Creating storyboards 2b. Defining the objects 2c. Defining the connections between the screens the user will see 3. Coding the program 4. Translating the program into machine language 5. Testing the program 6. Putting the program into production 7. Maintaining the program Programming Logic and Design, Eighth Edition
  • 23. Developing an Event-Driven Application (continued) 23 Table 12-3 Insurance premiums based on customer characteristics Programming Logic and Design, Eighth Edition
  • 24. Creating Wireframes 24 • Wireframe – A picture or sketch of a screen the user will see when running a program – Also called a page schematic or screen blueprint – Can be pencil sketches or produced by software applications Programming Logic and Design, Eighth Edition
  • 25. Creating Storyboards 25 • Storyboard – Contains a series of wireframes that represent a user’s experience with the proposed software • GUI storyboards – Represent “snapshot” views of the screens the user will encounter during the run of a program Programming Logic and Design, Eighth Edition
  • 26. Creating Storyboards (continued) 26 Figure 12-5 Storyboard for insurance program Programming Logic and Design, Eighth Edition
  • 27. 27 Defining the Storyboard Objects in an Object Dictionary • An event-driven program may contain dozens or even hundreds of objects • Object dictionary – A list of the objects used in a program – Includes which screens they are used on and whether any code, or script, is associated with them Programming Logic and Design, Eighth Edition
  • 28. 28 Defining the Storyboard Objects in an Object Dictionary (continued) Figure 12-6 Object dictionary for insurance premium program Programming Logic and Design, Eighth Edition
  • 29. 29 Defining Connections Between the User Screens • Draw the connections between the screens to show how they interact • Interactivity diagram – Shows the relationship between screens in an interactive GUI program • One screen may lead to different screens depending on the options the user selects at any one screen Programming Logic and Design, Eighth Edition
  • 30. 30 Defining Connections Between the User Screens (continued) Figure 12-7 Interactivity diagram for insurance premium program Figure 12-8 Interactivity diagram for a complicated program Programming Logic and Design, Eighth Edition
  • 31. 31 Planning the Logic • Design the screens • Define the objects • Define how the screens will connect • Then start to plan the class • Create the component onto which all the GUI elements are placed – Might use a class with a name such as Screen, Form, or Window Programming Logic and Design, Eighth Edition
  • 32. 32 Figure 12-9 Component definitions for first screen of insurance program Programming Logic and Design, Eighth Edition Planning the Logic (continued)
  • 33. 33 • Register components – Sign them up so that they can react to events initiated by other components • Container – A class of objects whose main purpose is to hold other elements – Contains methods that allow you to set physical properties such as height and width – Contains methods that allow you to add the appropriate components to a container Planning the Logic (continued) Programming Logic and Design, Eighth Edition
  • 34. 34 Figure 12-10 Statements that create screen1 Figure 12-11 Statements that define and create screen2 and its components Planning the Logic (continued) Programming Logic and Design, Eighth Edition
  • 35. 35 Figure 12-12 Pseudocode for calcRoutine() method of insurance premium programProgramming Logic and Design, Eighth Edition Planning the Logic (continued)
  • 36. 36 Understanding Threads and Multithreading • Thread – The flow of execution of one set of program statements • Many applications follow a single thread • A computer’s central processing unit (CPU) can execute only one statement at a time regardless of its processor speed • A computer with multiple CPUs can execute multiple instructions simultaneously Programming Logic and Design, Eighth Edition
  • 37. 37 Understanding Threads and Multithreading (continued) • Multithreading – Using multiple threads of execution – Multiple threads share the CPU’s time for a single processor • Use multithreading to improve the performance of your programs – More user friendly • Object-oriented languages often contain a built-in Thread class – Contains methods to help handle multiple threads Programming Logic and Design, Eighth Edition
  • 38. 38 Figure 12-14 Executing multiple tasks as single threads in a single-processor system Figure 12-15 Executing multiple threads in a single-processor system Understanding Threads and Multithreading (continued) Programming Logic and Design, Eighth Edition
  • 39. 39 • Code carefully to avoid deadlock and starvation – Two or more threads wait for each other – Threads are abandoned when other threads have all resources • Techniques like thread synchronization avoid problems such as: – Two clerks accessing the same record, and the first one updating it while the other is still viewing it – The second user still thinks the data is accurate Understanding Threads and Multithreading (continued) Programming Logic and Design, Eighth Edition
  • 40. 40 Creating Animation • Animation – A rapid sequence of still images – Each is slightly different from the previous one – Produces the illusion of movement • Object-oriented languages offer built-in classes used to draw geometric figures on the screen • Position – Horizontal: x-axis, x-coordinate – Vertical: y-axis, y-coordinate Programming Logic and Design, Eighth Edition
  • 41. Creating Animation (continued) 41 Figure 12-16 Selected screen coordinate positions Programming Logic and Design, Eighth Edition
  • 42. Creating Animation (continued) 42 • MovingCircle class – Moves a circle across the screen – Constants SIZE and INCREASE – drawCircle() method – sleep() method Figure 12-17 The MovingCircle class Programming Logic and Design, Eighth Edition
  • 43. 43 Figure 12-18 Output of the MovingCircle application Creating Animation (continued) Programming Logic and Design, Eighth Edition
  • 44. Summary 44 • Graphical user interface (GUI) – Users manipulate objects such as buttons and menus – Listeners are “interested in” an event – Common user events involve mouse events • Common GUI components include labels, text boxes, buttons, check boxes, check box groups, option buttons, and list boxes • Interface should be natural, predictable, attractive, easy to read, and nondistracting Programming Logic and Design, Eighth Edition
  • 45. Summary (continued) 45 • Event-driven applications require wireframes and storyboards, defining objects and defining connections the user will see • Thread – The flow of execution of one set of program statements • Animation – A rapid sequence of still images Programming Logic and Design, Eighth Edition