Event Driven Programming

Slides:



Advertisements
Similar presentations
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Advertisements

Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Event-based Programming Roger Crawfis. Window-based programming Most modern desktop systems are window-based. Non-window based environment Window based.
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
Unit 20: Event Driven Programming
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
FLTK Tutorial.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Introduction to Windows Programming
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Object Oriented Programming.  Interface  Event Handling.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Creating User Interfaces Event-Driven Programming.
1 Chapter 3 Event-Driven Programming. 2 Objectives F To explain the concept of event-driven programming (§12.2). F To understand event, event source,
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
1 Lecture 8: User Interface Components with Swing.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Events and Event Handling
Chapter 14 Event-Driven Programming
Topics Graphical User Interfaces Using the tkinter Module
Event Loops and GUI Intro2CS – weeks
CompSci 230 S Software Construction
Chapter 12 Event-Driven Programming
Responding to Events Event Handling in Java
Introduction to Event-Driven Programming
Chapter Topics 15.1 Graphical User Interfaces
Event-driven programming
Event loops 16-Jun-18.
Goals Give student some idea what this class is about
Processing Timer Events
CSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation
Event Driven Programming Dick Steflik
Lesson 1: Buttons and Events – 12/18
CSE 331 Software Design and Implementation
Introduction to Events
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Windows Desktop Applications
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
EE 422C Java FX.
Basic Elements of The GUI
Introduction to Computing Using Java
CSE 331 Software Design and Implementation
Event loops.
Event Driven Systems and Modeling
Windowing Push-Pull Systems
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Event Driven Programming Anatomy – Handle
Events, Event Handlers, and Threads
Chapter 15: GUI Applications & Event-Driven Programming
Event loops 8-Apr-19.
Tonga Institute of Higher Education
Chapter 13: Handling Events
Event loops.
Chapter 15 Event-Driven Programming and Animations Part 1
CSE 331 Software Design & Implementation
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

Event Driven Programming CSCE 121 J. Michael Moore

Procedural Programming So far we’ve done procedural programming. We control the flow of the program…

Event Driven We respond to events. Event framework controls the flow of the program. Events Sensor Data Mouse Clicks User input Common in GUI (Graphical User Interface) Programming

Flow Wait for Events Event Loop Process Event

Widgets Widgets are anything placed into a window (e.g. Button, Box, Slider…) When events occur they are directed to the appropriate widget.

Not all listed Events Mouse Keyboard Timer Resize Press / Release Drag Over Keyboard Timer Resize Not all listed

Processing Events Write functions / methods to respond to particular events.

Getting Events (First Way) Objects that receive events can override a handler function that is called when an event occurs for the widget. The generic button does not know what we want it to do when it is pressed. Generally we subclass the widget so we can add our own data members and functions. In the child class we write a handler function that does the appropriate action.

Getting Events (Second Way) Sometimes, other areas of code need to know when an event occurs with a particular widget. We want to register with the widget to get notified when events occur in the widget we are watching. Listener, Callback After registering, any time the widget gets an event, the listener/callback is notified.

Getting Events (Second Way) Some systems are more refined in the listener system. In Java You can register for specific types of events You can have have multiple listeners. With FLTK You can only register for all events. In that case you have to check and make sure it is the right type of event. Only one listener can be registered. You can overcome by letting the single listener inform others as well.

Starting a GUI program Set up data and any GUI elements that need to be shown. Start event loop. Once loop is running, handlers and registered listeners / callbacks will be executed based on events that happen. When those functions return, the event loop will continue.

Be Careful Does not work like procedural programming. Example: Dialogue window Catch event to display Window. (return to event loop) User inputs data into window and triggers an event. (e.g. “submit” button) Catch event to “submit,” get data input into window, process data, and hide/close window. (return to event loop) NOTE: return to event loop requires no special action, just end the function as we have always done.

References http://eventdrivenpgm.sourceforge.net/ https://en.wikipedia.org/wiki/Event-driven_programming