Event loopsProgramming in prehistoric timesVery early interactive programsCommand-driven programs (20 years ago)Modern event-driven programsJava hides the event loopBuilding a GUIVocabulary IVocabulary IIThe EndJan 14, 2019Event loops2Programming in prehistoric timesEarliest programs were all “batch” processingThere was no interaction with the userInputOutputProcess3Very early interactive programsBASIC was an early interactive languageStill a central computer, with terminalsStyle of interaction was “filling out forms”Process inputAsk user for inputAsk user for inputProcess inputetc.4Command-driven programs(20 years ago)Allow the user to enter “commands” Much more flexibleStill only a single source of inputsNot good enough for modern programsAsk user for commandRead and parsecommandExecute commandquit5Modern event-driven programsMultiple sources of inputmouse clickskeyboardtimersexternal eventsA new program structure is requiredWait for eventDispatch eventQuit6Java hides the event loopThe event loop is built into Java GUIsGUI stands for Graphical User InterfaceInteracting with a GUI component (such as a button) causes an event to occurAn Event is an objectYou create Listeners for interesting eventsThe Listener gets the Event as a parameter7Building a GUITo build a GUI in Java,Create some ComponentsUse a layout manager to arrange the Components in a windowAdd Listeners, usually one per ComponentPut code in the Listeners to do whatever it is you want doneThat's it!Of course, there are a lot of details....8Vocabulary IEvent – an object representing an external happening that can be observed by the programevent-driven programming – A style of programming where the main thing the program does is respond to Eventsevent loop – a loop that waits for an Event to occur, then dispatches it to the appropriate codeGUI – a Graphical User Interface (user interacts with the program via things on the screen)9Vocabulary IIComponent – an interface element, such as a Button or a TextFieldLayout Manager – an object (provided by Java) that arranges your Components in a windowListener – an object you create to execute some code appropriate when an Event occurs10The
View Full Document