preview

Sequential vs. Event-Driven Programming

Better Essays

Sequential vs. Event-driven Programming
Reacting to the user

Outline
Sequential programming GUI program organization Event-driven programming Modes

Sequential Programming
In sequential programs, the program is under control The user must synchronize with the program:
Program tells user it is ready for input User enters input and it is processed

Examples:
Command-line prompts (DOS, UNIX) LISP interpreters

Shouldn’t the program be required to synchronize with the user?

Sequential Programming (2)
Flow of a typical sequential program
Prompt the user Read input from the keyboard Parse the input (determine user action) Evaluate the result Generate output Repeat

Example
DemoTranslateEnglishConsole.java

Prompt the …show more content…

Interfaces vs. Classes
The definition of a class includes both the design of the class and its implementation Sometimes it is desirable only to design a class, leaving the implementation for later This is accomplished using an interface An interface contains only the design of a class
Includes signatures for its members (methods and fields) No implementation is provided

Characteristics of Interfaces
Interfaces… Do not have instance variables You cannot instantiate an object of an interface Include only abstract methods Methods have a signature (i.e., a name, parameters, and return type) Methods do not have an implementation (i.e., no code) Include only public methods and fields Does not make sense to define private members if the public members that could potentially use them are themselves not implemented

Listener Example
The signature of our extended JFrame class includes the clause implements KeyListener This means our class must include definitions for the methods of the KeyListener listener Thus… public void keyPressed(KeyEvent ke) {} public void keyReleased(KeyEvent ke) {} public void keyTyped(KeyEvent ke) {}

Our implementation includes the code we

Get Access