View Full Document

Event loops



View the full content.
View Full Document
View Full Document

9 views

Unformatted text preview:

Event loops Programming in prehistoric times Earliest programs were all batch processing There was no interaction with the user BASIC was an early interactive language Still a central computer with terminals Style of interaction was filling out forms forms Ask user for input Process input Ask user for input Process input etc Process Output Command driven programs 20 years ago Very early interactive programs Input Allow the user to enter commands commands Much more flexible Still only a single source of inputs Not good enough for modern programs Ask user for command Read and parse command Execute command quit 1 Modern event driven programs The rise of Graphical User Interfaces forced a change Multiple sources of input Wait for event Java hides the event loop mouse clicks keyboard timers external events Dispatch event Quit A new program structure is required Also useful for programming distributed system components e g Internet programs too To build a GUI in Java Create some Components Components Use a layout manager to arrange the Components Components in a window Add Listeners Listeners usually one per Component Put code in the Listeners Listeners to do whatever it is you want done That s it Of course there are a lot of details GUI stands for Graphical User Interface Interacting with a GUI component such as a button causes an event to occur An Event is an object You create Listeners Listeners for interesting events The Listener gets the Event as a parameter Vocabulary I Building a GUI The event loop is built into Java GUIs event an object representing an external happening that can be observed by the program eventevent driven programming A style of programming where the main thing the program does is respond to events event loop a loop that waits for an event to occur then dispatches it to the appropriate code GUI a Graphical User Interface user interacts with the program via things on the screen 2 Vocabulary II Component an interface element such as a Button or a



Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Event loops and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Event loops and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?