C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.

Slides:



Advertisements
Similar presentations
Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Advertisements

Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
MSc. Publishing on WWW JavaScript. What is JavaScript? A scripting language devised by Netscape Adds functionality to web pages by: Embedding code into.
Automating Tasks With Macros
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 16 Event-Driven Programming Of all men’s miseries.
Chapter 11 Exception Handling and Event Handling.
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
Slide 1 ICS 012 Visual Programming I Ahmed Esmat Second.
TC2-Computer Literacy Mr. Sencer February 8, 2010.
ProgrammingLanguages Programming Languages Event-Driven Visual Programming Languages This lecture discusses the basic concepts of the event-driven programming.
Applets Java API.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Welcome to CIS 083 ! Events CIS 068.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R T E N Event-Driven Programming.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Computer Programming 12 Mr. Jean March 19 th, 2013.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Concurrent Programming and Threads Threads Blocking a User Interface.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
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.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
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,
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
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.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 16 Event-Driven Programming Of all men’s miseries.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
GUI Programming using Java - Event Handling
Java Events. Java Events Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows.
Chapter Topics 15.1 Graphical User Interfaces
Event-driven programming
Event loops 16-Jun-18.
Event Driven Programming Dick Steflik
Understanding an App’s Architecture
Ellen Walker Hiram College
Event Driven Programming
Event loops.
Event Driven Systems and Modeling
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Chapter 15: GUI Applications & Event-Driven Programming
Event loops 8-Apr-19.
Event loops.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan

Background: Previous programming paradigms have emphasized the process for solving a problem. Once the program was complete we would:  provide input  run the program  display the answer(s) Things always happened in the same sequence. The program always terminated when the process was complete (except for some Prolog programs we will not mention).

Background: Event-driven programs do not have a set sequence of instructions to execute. They also do not have a predetermined finish. The most common example of event-driven programming is found in graphical user interfaces (GUIs):  M$ Windows  Apples Mac OS  X11 under *nix Other applications include embedded systems, control systems, sensor systems like home security, etc.

Event-driven Languages: Support of even-driven programming is often grafted on to existing languages, for example X11 is implemented as a set of function libraries under C and class libraries under C++. Some languages were designed around the needs of event-driven applications such as Visual Basic and Tcl/Tk. With the advent of the word wide web (WWW) event- driven programming has gained in popularity as a way to add interaction to web pages. Such interaction is programmed in a number of languages including JavaScript and Java. We will be using Java to implement Applets, programs intended to run inside a web browser.

Imperative vs. Event-Driven Paradigms Figure 10.1 Computation is a function from its input to its output, made up of a sequence of steps that produce some result as its goal. ** Computation is a community of persistent entities coupled together by their ongoing interactive behavior. Beginning and end are special case that can often be ignored.

Event-driven Programs Input to event-driven programs come from event sources; sensors, input devices, objects on a web page. Events occur asynchronously and are placed in an event queue as they arise. Events are removed from the event queue and processed (“handled”) by the program’s main processing loop. As a result of handling an event the program may produce output or modify the value of a state variable. There is no predefined starting or stopping point. Java provides support for event-driven programming through certain classes and methods that can be used to design program interaction.

Java Class AWTEvent and Its Subclasses* Figure 10.2 Events in Java are defined by subclasses of the AWTEvent abstract class.

Java Event Classes Every event source in a program can generate an event that is a member of one of the classes on the previous slide. For example, if a Button is an event source, it generates events that are members of the ActionEvent class. Objects that can be event sources are members of subclasses of the Component abstract class. This class and its subclasses are shown on the next slide, where we will find the Button object.

Subclasses of Component That Can Be Sources of Events Figure 10.3

Java EventListener Class Interface: For a program to handle an event it must be equipped with a listener that will recognize when a particular event has occurred. For example, for a program to be able to “hear” that a button has been selected it must send an addActionListener message to the button object. The EventListener class and its subclasses provide the interface for recognizing events by setting up appropriate listeners for component objects. The EventListener class interface and its subclasses are shown on the next slide.

Java EventListener Class Interface and Its Subclasses* Figure 10.4 To respond to events we need to implement special methods called handlers. Each class of events predefines the names of the handlers that can be written for it…

Handlers Required for Button, Menu, Text Typing, and Mouse Events Figure 10.5

Initial Frame Design for a Graphical Drawing Tool Figure 10.7

Overall Structure of a Java Applet Figure 10.6

Next time… example : Writing A Java Applet