SlideShare une entreprise Scribd logo
1  sur  45
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

Contenu connexe

Tendances

Z Buffer Optimizations
Z Buffer OptimizationsZ Buffer Optimizations
Z Buffer Optimizationspjcozzi
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in JavaSpotle.ai
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithmAnkit Garg
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javajayc8586
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin schedulingRaghav S
 
Uml Presentation
Uml PresentationUml Presentation
Uml Presentationmewaseem
 
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...Gerke Max Preussner
 
Image compression using discrete wavelet transform
Image compression using discrete wavelet transformImage compression using discrete wavelet transform
Image compression using discrete wavelet transformHarshal Ladhe
 
First fit , Best fit, Worst fit
First fit , Best fit, Worst fitFirst fit , Best fit, Worst fit
First fit , Best fit, Worst fitShahzeb Amjad
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...Unity Technologies
 

Tendances (20)

Z Buffer Optimizations
Z Buffer OptimizationsZ Buffer Optimizations
Z Buffer Optimizations
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
RUP
RUPRUP
RUP
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin scheduling
 
Prototyping model
Prototyping modelPrototyping model
Prototyping model
 
Uml Presentation
Uml PresentationUml Presentation
Uml Presentation
 
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
East Coast DevCon 2014: Concurrency & Parallelism in UE4 - Tips for programmi...
 
[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP
 
Lecture 5 process concept
Lecture 5   process conceptLecture 5   process concept
Lecture 5 process concept
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Image compression using discrete wavelet transform
Image compression using discrete wavelet transformImage compression using discrete wavelet transform
Image compression using discrete wavelet transform
 
UML tutorial
UML tutorialUML tutorial
UML tutorial
 
First fit , Best fit, Worst fit
First fit , Best fit, Worst fitFirst fit , Best fit, Worst fit
First fit , Best fit, Worst fit
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Java architecture
Java architectureJava architecture
Java architecture
 
Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...Getting started with High-Definition Render Pipeline for games- Unite Copenha...
Getting started with High-Definition Render Pipeline for games- Unite Copenha...
 

Similaire à Chapter 12 Lecture: GUI Programming, Multithreading, and Animation

CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)Dr. Ahmed Al Zaidy
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfBernardVelasco1
 
chapter12 - Software engineering.pdf
chapter12 - Software engineering.pdfchapter12 - Software engineering.pdf
chapter12 - Software engineering.pdfsatonaka3
 
PT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - AndroidPT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - Androiddrjuniornet
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and DesignMay Belleza
 
Automatic Graphical Design Generator
Automatic Graphical Design GeneratorAutomatic Graphical Design Generator
Automatic Graphical Design GeneratorIRJET 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 InfrastructureEyad Almasri
 
EXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNSEXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNSROHISIVAM
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
 
Computer graphics Applications and System Overview
Computer graphics Applications and System OverviewComputer graphics Applications and System Overview
Computer graphics Applications and System OverviewRAJARATNAS
 
User Interface Design.pptx
User Interface Design.pptxUser Interface Design.pptx
User Interface Design.pptxssuserd67eb9
 

Similaire à Chapter 12 Lecture: GUI Programming, Multithreading, and Animation (20)

Unit 2
Unit 2Unit 2
Unit 2
 
CREATIVE TECHNOLOGY 7 QI-L1
CREATIVE TECHNOLOGY 7 QI-L1CREATIVE TECHNOLOGY 7 QI-L1
CREATIVE TECHNOLOGY 7 QI-L1
 
CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
 
Climberreport
ClimberreportClimberreport
Climberreport
 
chapter12 - Software engineering.pdf
chapter12 - Software engineering.pdfchapter12 - Software engineering.pdf
chapter12 - Software engineering.pdf
 
ITE 101 - Week 5
ITE 101 - Week 5ITE 101 - Week 5
ITE 101 - Week 5
 
PT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - AndroidPT GTUG 1st Technical Tession - Android
PT GTUG 1st Technical Tession - Android
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and Design
 
Automatic Graphical Design Generator
Automatic Graphical Design GeneratorAutomatic Graphical Design Generator
Automatic Graphical Design Generator
 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report
 
Project
ProjectProject
Project
 
GUI_part_1.pptx
GUI_part_1.pptxGUI_part_1.pptx
GUI_part_1.pptx
 
Android Infrastructure
Android InfrastructureAndroid Infrastructure
Android Infrastructure
 
EXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNSEXPLORING VARIOUS UI INTERACTION PATTERNS
EXPLORING VARIOUS UI INTERACTION PATTERNS
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Visual basic
Visual basicVisual basic
Visual basic
 
Computer graphics Applications and System Overview
Computer graphics Applications and System OverviewComputer graphics Applications and System Overview
Computer graphics Applications and System Overview
 
1. ch 1-introduction
1. ch 1-introduction1. ch 1-introduction
1. ch 1-introduction
 
User Interface Design.pptx
User Interface Design.pptxUser Interface Design.pptx
User Interface Design.pptx
 

Plus de Nicole Ryan

Testing and Improving Performance
Testing and Improving PerformanceTesting and Improving Performance
Testing and Improving PerformanceNicole Ryan
 
Optimizing a website for search engines
Optimizing a website for search enginesOptimizing a website for search engines
Optimizing a website for search enginesNicole 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 modelNicole Ryan
 
Working with Video and Audio
Working with Video and AudioWorking with Video and Audio
Working with Video and AudioNicole Ryan
 
Working with Images
Working with ImagesWorking with Images
Working with ImagesNicole Ryan
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and SetsNicole Ryan
 
Creating Visual Effects and Animation
Creating Visual Effects and AnimationCreating Visual Effects and Animation
Creating Visual Effects and AnimationNicole Ryan
 
Creating and Processing Web Forms
Creating and Processing Web FormsCreating and Processing Web Forms
Creating and Processing Web FormsNicole Ryan
 
Organizing Content with Lists and Tables
Organizing Content with Lists and TablesOrganizing Content with Lists and Tables
Organizing Content with Lists and TablesNicole Ryan
 
Social media and your website
Social media and your websiteSocial media and your website
Social media and your websiteNicole Ryan
 
Working with Links
Working with LinksWorking with Links
Working with LinksNicole Ryan
 
Formatting text with CSS
Formatting text with CSSFormatting text with CSS
Formatting text with CSSNicole Ryan
 
Laying Out Elements with CSS
Laying Out Elements with CSSLaying Out Elements with CSS
Laying Out Elements with CSSNicole Ryan
 
Getting Started with CSS
Getting Started with CSSGetting Started with CSS
Getting Started with CSSNicole Ryan
 
Structure Web Content
Structure Web ContentStructure Web Content
Structure Web ContentNicole Ryan
 
Getting Started with your Website
Getting Started with your WebsiteGetting Started with your Website
Getting Started with your WebsiteNicole 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 2Nicole Ryan
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: ModularityNicole Ryan
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: ArraysNicole Ryan
 

Plus de Nicole Ryan (20)

Testing and Improving Performance
Testing and Improving PerformanceTesting and Improving Performance
Testing and Improving Performance
 
Optimizing a website for search engines
Optimizing a website for search enginesOptimizing a website for search engines
Optimizing a website for search engines
 
Inheritance
InheritanceInheritance
Inheritance
 
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
 
Working with Video and Audio
Working with Video and AudioWorking with Video and Audio
Working with Video and Audio
 
Working with Images
Working with ImagesWorking with Images
Working with Images
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
 
Creating Visual Effects and Animation
Creating Visual Effects and AnimationCreating Visual Effects and Animation
Creating Visual Effects and Animation
 
Creating and Processing Web Forms
Creating and Processing Web FormsCreating and Processing Web Forms
Creating and Processing Web Forms
 
Organizing Content with Lists and Tables
Organizing Content with Lists and TablesOrganizing Content with Lists and Tables
Organizing Content with Lists and Tables
 
Social media and your website
Social media and your websiteSocial media and your website
Social media and your website
 
Working with Links
Working with LinksWorking with Links
Working with Links
 
Formatting text with CSS
Formatting text with CSSFormatting text with CSS
Formatting text with CSS
 
Laying Out Elements with CSS
Laying Out Elements with CSSLaying Out Elements with CSS
Laying Out Elements with CSS
 
Getting Started with CSS
Getting Started with CSSGetting Started with CSS
Getting Started with CSS
 
Structure Web Content
Structure Web ContentStructure Web Content
Structure Web Content
 
Getting Started with your Website
Getting Started with your WebsiteGetting Started with your Website
Getting Started with your Website
 
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
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: Modularity
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: Arrays
 

Dernier

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
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
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
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
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
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
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
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
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 

Dernier (20)

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
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
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
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
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
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
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.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)
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 

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