Intermediate Algebra Math 115 - First Day

Download Report

Transcript Intermediate Algebra Math 115 - First Day

Console and GUI Programs
Two Models for Programming
Copyright © 2001-2012 Curt Hill
Paradigms
• Pronounced Pair-a-dime
• Definition: A model or example
• A way of approaching a situation
that affects every action that is
taken
Copyright © 2001-2012 Curt Hill
Operating Systems
• A set of programs that runs the
computer
• Performs a number of important
functions:
–
–
–
–
Interprets user commands
Establishes a file system
Handles errors
Among other things
Copyright © 2001-2012 Curt Hill
User commands
• Early operating systems used console
input
– These include DOS, UNIX, VMS
• Later operating systems adopted a GUI
– Graphical User Interface
– Pronounced “Gooey”
– These include Mac OS, Windows, Xwindows
• The two use different computing models
Copyright © 2001-2012 Curt Hill
Simple Example
• The Console and GUI program will
be demonstrated using a program to
compute greatest common factor
• Each program will receive two
numbers from the user
• Compute GCF using Euclid’s method
Copyright © 2001-2012 Curt Hill
Euclid’s Method for GCF
• Make the larger num1 and smaller
num2
• Divide num1 by num2 and keep
remainder
• Set num1 to num2
• Set num2 to remainder
• Repeat the division until num2 < 2
Copyright © 2001-2012 Curt Hill
The Console Version
This program computes the Greatest
Common Factor using Euclid's method
Enter the first number
323
Enter the second number
437
GCF is 19
Do you want to do another?
n
Copyright © 2001-2012 Curt Hill
The GUI Version
Copyright © 2001-2012 Curt Hill
The Console Screen
• Usually a list of messages and inputs
• When a program writes a message
– Appears on the bottom of the list
– All previous messages scroll up
• When input is needed the user types
it at bottom
• No need for a pointing device, like a
mouse
Copyright © 2001-2012 Curt Hill
The Console Paradigm
• The model for computing is that the
program is in control
• It starts executing at some designated
point
• Continues from there
• If it needs input, it initiates the input
– Prompts user and then reads
• The order of input is determined by
program
Copyright © 2001-2012 Curt Hill
Form of Console Program
OS
Pgm
Subr
Subr
Subr
Subr
Subr
Service
Copyright © 2001-2012 Curt Hill
Subr
Service
Form Again
• In a console program the Operating
System starts the main program
• This program may in turn call
subroutines
– Methods, functions, procedures
– These may call others
• Some will call OS services
– Such as input and output
Copyright © 2001-2012 Curt Hill
Other Console Comments
• Interrupts are used by OS but not a
factor in programs
• Interrupt:
– A response to an event whose timing is
unpredictable
• When interrupt processing is done,
whatever was running is resumed
Copyright © 2001-2012 Curt Hill
The GUI Screen
• Usually a series of Windows
• Each window has certain
characteristics and controls
• A control is an item within the
window
– Buttons
– Edit boxes
– List boxes
Copyright © 2001-2012 Curt Hill
GUI History
• Developed at Xerox Palo Alto Research
Center
– Alan Kay and others
– They were not going to market it
• Jobs of Apple saw it and used for Mac
• Gates developed Windows because of
success of Mac
• Xwindows was developed for UNIX
independently
Copyright © 2001-2012 Curt Hill
WIMP
• The classic GUI is also known as
WIMP
–
–
–
–
Windows
Icons
Menus
Pointer (mouse or trackball)
Copyright © 2001-2012 Curt Hill
The GUI Paradigm
• The model for computing is that the
operating system and user is in control
• The program starts
– It displays its windows through the operating
system
– Then waits for the user to do something
– Most of the execution is in response to some
user action, communicated by the OS
Copyright © 2001-2012 Curt Hill
A Sample Window
Copyright © 2001-2012 Curt Hill
Form of GUI Program
OS
Pgm
Subr
Subr
Subr
Subr
Service
Subr
Service
Copyright © 2001-2012 Curt Hill
Form Again
• In a GUI program the Operating
System starts the main program
• Main program describes how
windows are to be drawn
– It then returns to OS
• It also registers event handlers
– These are subroutines
– The events are things like a button click
– The subroutines may call other
subroutines as well OS services
• Event handlers are called by OS not
program Copyright © 2001-2012 Curt Hill
Objects
• In many programming environments
the controls are objects in the
technical sense
• An object is some data and code
that acts on it
• These objects often conform to the
PME model
Copyright © 2001-2012 Curt Hill
The PME Model
• Properties
– Data that is part of the object and
affects how it is used
• Methods
– Code that manipulates the object
• Events
– What to do if some user action occurs
Copyright © 2001-2012 Curt Hill
Properties
• Data that affects how the control looks or
acts
• Examples:
– The caption of a button or text of an edit box
– The alignment of the text
– The position: Left, top, width, height
• Some of these are modified at design time
and others at run time
Copyright © 2001-2012 Curt Hill
Methods
• Actions that can be performed at run-time
on the control
• Usually involves a substantial amount of
programming by someone else
• Clearing an edit box can be done by
assigning an empty string to its text
property or executing its Clear method
Copyright © 2001-2012 Curt Hill
Events
• When a button is clicked some action
needs to be taken
• An event is an action that occurs at
unpredictable times, so some code
handles it
• Examples:
– Mousing over a control
– Left click, right click or double click of a
control
– Receiving or losing focus
– Typing in a control
Copyright © 2001-2012 Curt Hill
Languages
• C++, SmallTalk, Java are full object
oriented languages
– Full support for objects, PME,
inheritance, polymorphism
– There are one or more full GUI
development environments
• Visual BASIC is half of an object
oriented language
– Has objects, most of PME
– No inheritance, no polymorphism
– Has a full GUI development
environment
Copyright © 2001-2012 Curt Hill