Sequential vs. Event-Driven Programming

1845 words 8 pages
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 user User input Output
…show more content…

In our example, we used this as the “specified key listener” Indeed, the current instance of our extended JFrame class (“this”) is a key listener because it implements the key listener methods Result: when a key pressed event occurs on the enterArea component, the keyPressed method in our extended JFrame class will execute!

Let’s Say That Again…
When a key pressed event occurs on the enterArea component, the keyPressed method in our extended JFrame class will execute!

Processing Events
Signature for the keyPressed method: public void

Related