Programming Logic and Design Seventh Edition Chapter 12 Event-Driven GUI Programming, Multithreading, and Animation.

Slides:



Advertisements
Similar presentations
Chapter 11 Designing the User Interface
Advertisements

AA high level programming language. IIt is created by Microsoft. UUses a graphical environment called the Integrated Development Environment (IDE).
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 13: Object-Oriented Programming
Chapter 1 Program Design
Chapter 14: Event-Driven Programming with Graphical User Interfaces
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
A Tour of Visual Basic BACS 287. Early History of Basic Beginners All-Purpose Symbolic Instruction Code An “Interpreted” teaching language English-like.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Integrated Development Environment Building Your First Project (A Step-By-Step Approach)
Introduction to Visual Basic (VB)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 8: More About OOP and GUIs.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
Welcome to CIS 083 ! Events CIS 068.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 9 Event-Driven Programming with Graphical User Interfaces
11.10 Human Computer Interface www. ICT-Teacher.com.
Visual C++ Programming: Concepts and Projects
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
CHAPTER TWO INTRODUCTION TO VISUAL BASIC © Prepared By: Razif Razali 1.
CC111 Lec7 : Visual Basic 1 Visual Basic(1) Lecture 7.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
INFORMATION SYSTEM – SOFTWARE TOPIC: GRAPHICAL USER INTERFACE.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Introduction to Programming and App Inventor. Introduction What is a computer program? Introducing App Inventor Getting hands on with App Inventor.
Programming Paradigms, Software Architectural Patterns, and MVC CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Collision Theory and Logic
Development Environment
Unit 2 Technology Systems
Introduction to Programming and Visual Basic
Chapter 8: More About OOP and GUIs
Chapter 1: An Introduction to Visual Basic 2015
Introduction to Computer CC111
Collision Theory and Logic
Introduction to Event-Driven Programming
Chapter Topics 15.1 Graphical User Interfaces
11.10 Human Computer Interface
Event-driven programming
Event loops 16-Jun-18.
DDC 1023 – Programming Technique
An Introduction to Computers and Visual Basic
Prototyping.
1. Introduction to Visual Basic
An Introduction to Computers and Visual Basic
Chap 7. Building Java Graphical User Interfaces
DB Implementation: MS Access Forms
Graphical User Interfaces -- Introduction
Event loops.
GRAPHICAL USER INTERFACE
DB Implementation: MS Access Forms
Event loops 17-Jan-19.
Event loops 17-Jan-19.
An Introduction to Computers and Visual Basic
Systems Design Project Deliverable 3
Chapter 15: GUI Applications & Event-Driven Programming
Event loops 8-Apr-19.
Event loops.
Event loops.
Event loops 19-Aug-19.
Chapter 4 Enhancing the Graphical User Interface
Programming Logic and Design Eighth Edition
Presentation transcript:

Programming Logic and Design Seventh 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, Seventh 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, Seventh Edition

Understanding Event-Driven Programming (continued) 4 Figure 12-1 Command prompt screen Programming Logic and Design, Seventh 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, Seventh Edition

6 Understanding Event-Driven Programming (continued) Figure 12-2 A GUI application that contains buttons and icons Programming Logic and Design, Seventh 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, Seventh 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, Seventh 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 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, Seventh Edition

User-Initiated Actions and GUI Components 10 Table 12-1 Common user-initiated events Programming Logic and Design, Seventh Edition

User-Initiated Actions and GUI Components (continued) 11 Table 12-2 Common GUI components Programming Logic and Design, Seventh Edition

User-Initiated Actions and GUI Components (continued) 12 Figure 12-3 Common GUI components Programming Logic and Design, Seventh 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, Seventh Edition

User-Initiated Actions and GUI Components (continued) 14 Figure 12-4 Button class Programming Logic and Design, Seventh 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, Seventh 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, Seventh 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, Seventh 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, Seventh 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, Seventh 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, Seventh 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, Seventh 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, Seventh Edition

Developing an Event-Driven Application (continued) 23 Table 12-3 Insurance premiums based on customer characteristics Programming Logic and Design, Seventh Edition

Creating Storyboards 24 Storyboard – Represents a picture or sketch of a screen the user will see when running a program GUI storyboards – Represent “snapshot” views of the screens the user will encounter during the run of a program Programming Logic and Design, Seventh Edition

Creating Storyboards (continued) 25 Figure 12-5 Storyboard for insurance program Programming Logic and Design, Seventh Edition

26 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, Seventh Edition

27 Defining the Storyboard Objects in an Object Dictionary (continued) Figure 12-6 Object dictionary for insurance premium program Programming Logic and Design, Seventh Edition

28 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, Seventh Edition

29 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, Seventh Edition

30 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, Seventh Edition

31 Figure 12-9 Component definitions for first screen of insurance program Programming Logic and Design, Seventh Edition

32 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, Seventh Edition

33 Figure Statements that create screen1 Figure Statements that define and create screen2 and its components Planning the Logic (continued) Programming Logic and Design, Seventh Edition

34 Figure Pseudocode for calcRoutine() method of insurance premium program Programming Logic and Design, Seventh Edition

35 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, Seventh Edition

36 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, Seventh Edition

37 Figure Executing multiple tasks as single threads in a single-processor system Figure Executing multiple threads in a single-processor system Understanding Threads and Multithreading (continued) Programming Logic and Design, Seventh Edition

38 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, Seventh Edition

39 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, Seventh Edition

Creating Animation (continued) 40 Figure Selected screen coordinate positions Programming Logic and Design, Seventh Edition

Creating Animation (continued) 41 MovingCircle class – Moves a circle across the screen – Constants SIZE and INCREASE – drawCircle() method – sleep() method Figure The MovingCircle class Programming Logic and Design, Seventh Edition

42 Figure Output of the MovingCircle application Creating Animation (continued) Programming Logic and Design, Seventh Edition

Summary 43 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, Seventh Edition

Summary (continued) 44 Event-driven applications require 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, Seventh Edition