Event Handling. Event Issues Event Dispatch – Bottom-up – Top-Down Windowing system must handle events for any application Windowing system may or may.

Slides:



Advertisements
Similar presentations
wwwcsif.cs.ucdavis.edu/~jacksoni
Advertisements

 Specifies a set of methods (i.e., method headings) that any class that implements that interface must have.  An interface is a type (but is not a class).
Lab 8: States and Transitions User Interface Lab: GUI Lab Oct. 16 th, 2013.
Event Handling. Overview How to listen (and not listen) for events Creating a utility library (and why you should) Typology of events Pairing event listeners.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Slide 1 ICS 012 Visual Programming I Ahmed Esmat Second.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Inner Classes. Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class Inner classes.
1 Introduction to Human Computer Interaction  Livecode Overview  Based on Livecode User Guide from RunRev Ltd. (2010) 
Event Handling in Java: Alternatives and Patterns Raja Sooriamurthi Information Systems Department Kelley School of Business Indiana.
Programming Languages and Paradigms Object-Oriented Programming.
CSC 298 Windows Forms.
Web Services Week 2 Aims: Getting started with creating simple C# applications within Visual Studio.NET Objectives: –An introduction to the syntax of C#.NET.
Chapter 11 Java AWT Part I: Mouse Events (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin,
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
ILM Proprietary and Confidential -
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Window and Events The structure of Interactive Software.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Pravin Yannawar, DOCS, NMU Jalgaon. Basic Java : Event handling in AWT and Swing 2 Objectives of This Session Explain the Event handling mechanism & demonstrate.
MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
2-Dec-15 Inner Classes. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class.
Java Inner Classes. Interfaces interface KeyListener { public void keyPressed(KeyEvent e); public void keyReleased(KeyEvent e); public void keyTyped(KeyEvent.
2-Dec-15 Inner Classes By Alguien Soy. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
A comparison of C-Sharp and Java Zunaid Jogee Supervisor: T. Stakemire.
Duke CPS Modules in Java l Classes that are related should be grouped together, may even share access to otherwise private methods/instance variables.
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
CISC 110 Day 6 Introduction to Events. Outline Event-Driven Programming Event Classes Hierarchy –Event Class –Mouse Events –Keyboard Events Registering.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 8 – Event Handling Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Inner Classes.
The structure of Interactive Software
Topic: Inner Classes Course : JAVA PROGRAMMING Paper Code: ETCS-307 Faculty : Dr. Prabhjot Kaur Reader, Dept. of IT 1.
Welcome To java
Inner Classes 27-Dec-17.
Chapter 15 Event-Driven Programming and Animations
“Form Ever Follows Function” Louis Henri Sullivan
Interface.
Module 5: Common Type System
Inner Classes 11/14/ Dec-04 inner_classes.ppt.
Introduction to Java Programming
Inner Classes 29-Nov-18.
Development The Foundation Window.
Web Design & Development Lecture 13
Java Inner Classes.
Inner Classes 17-Apr-19.
Inner Classes 21-Apr-19.
Inner Classes 1-May-19.
Inner Classes 11-May-19.
Inner Classes 18-May-19.
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
Inner Classes.
CSG2H3 Object Oriented Programming
Inner Classes 25-Oct-19.
Presentation transcript:

Event Handling

Event Issues Event Dispatch – Bottom-up – Top-Down Windowing system must handle events for any application Windowing system may or may not assume compiler cooperation Design-time vs. Runtime

Event Handling Properties Ease of programming Efficiency of event handling Code reliability Support for IDE (Interactive Design Environment) Scalable to large user interfaces

Event Things to Know For each approach – How it Works – Advantages – Disadvantages

Event Tables Advantages – Simple to implement – Each window is its own system Disadvantages – Debugging mistakes – No IDE help 0 MouseUp() 1 MouseDown() 2 MouseMove() …… 0 MouseUp() 1 MouseDown() 2 MouseMove() …… 0 MouseUp() 1 MouseDown() 2 MouseMove() ……

void rootWindowProc(Event, WindowData) {switch(Event.type) {..... } void aWindowProc(Event, WindowData) {switch(Event.type) {..... } void someWProc(Event, WindowData) {switch(Event.type) {..... default: superWProc(... ) } WindowProc Advantages – Simple – Window modular – Primitive inheritance Disadvantages – No IDE help – Debugging issues again

Class Inheritance public class Widget {public void mouseDown(int x, int y, int button) {default behavior } public void mouseUp(int x, int y, int button) {default behavior } public void keyInput(char key) {default behavior }... } public class PigTickler extends Widget {public void mouseDown(int x, int y, int button) {poke the pig } public void mouseUp(int x, int y, int button) {wiggle your finger } public void keyInput(char key) {rename the pig}... }

Window -> Object : Widget Pigs: DualPane Pane1 : PigTickler Scroll2 : ScrollBar Pane2 : PigTickler Scroll1 : ScrollBar MouseDown -> selectedWindow.myObject.MouseDown( new MouseEvent(…..) )

Class Inheritance public class Widget {public void mouseDown(int x, int y, int button) {default behavior } public void mouseUp(int x, int y, int button) {default behavior } public void keyInput(char key) {default behavior }... } public class PigTickler extends Widget {public void mouseDown(int x, int y, int button) {poke the pig } public void mouseUp(int x, int y, int button) {wiggle your finger } public void keyInput(char key) {rename the pig}... } 0: mouseDown 1: mouseUp 2: keyInput 3:.. Virtual Table 0: mouseDown 1: mouseUp 2: keyInput 3:..

Window -> Object : Widget Pigs: DualPane Pane1 : PigTickler Scroll2 : ScrollBar Pane2 : PigTickler Scroll1 : ScrollBar MouseDown -> selectedWindow.myObject.MouseDown( new MouseEvent(…..) ) 0: 1: 0: 1: 0: 1:

Class Inheritance Advantages – Language assistance – Debugging – Modular Disadvantages – Virtual table size – Inheritance restrictions (see scroll bar handling) public class Widget {public void mouseDown(int x, int y, int button) {default behavior } public void mouseUp(int x, int y, int button) {default behavior } public void keyInput(char key) {default behavior }... }

Listeners Advantages – Modularity of event types – Separation from inheritance – Reflection in the IDE Disadvantages – All events of a particular type go the same place class CoolEvent { information about the event } interface CoolListener { void coolHappened(CoolEvent e); } class DoCoolStuff { private Vector listeners; public void addCoolListener(CoolListener c) { listeners.add(c); } public void remCoolListener(CoolListener c) { listeners.remove(c); } protected void coolHappened(CoolEvent e) { for (CoolListener c: listeners) { c.coolHappened(e); } }

class ScrollBar extends Widget { private Vector listeners; public void addScrollListener(ScrollListener c) { listeners.add(c); } public void remScrollListener(ScrollListener c) { listeners.remove(c); } protected void scrollHappened(ScrollEvent e) { for (ScrollListener c: listeners) { c.scrollHappened(e); } }

class ScrollBar extends Widget { private Vector listeners; public void addScrollListener(ScrollListener c) { listeners.add(c); } public void remScrollListener(ScrollListener c) { listeners.remove(c); } protected void scrollHappened(ScrollEvent e) { for (ScrollListener c: listeners) { c.scrollHappened(e); } } class Browser extends Widget implements ScrollListener { public void scrollHappened(ScrollEvent e) { if (e.isVertical() ) scroll vertical; else scroll horizontal; }

class ScrollBar extends Widget { private Vector listeners; public void addScrollListener(ScrollListener c) { listeners.add(c); } public void remScrollListener(ScrollListener c) { listeners.remove(c); } protected void scrollHappened(ScrollEvent e) { for (ScrollListener c: listeners) { c.scrollHappened(e); } } class Browser extends Widget implements ScrollListener { public void scrollHappened(ScrollEvent e) { if (e.isVertical() ) scroll vertical; else scroll horizontal; } class Firefox { public void main(String args[]) { hScroll=new ScrollBar(); vScroll=new ScrollBar(); browse = new Browser(); hScroll.addScrollListener(browse); vScroll.addScrollListener(browse); }

Listeners Advantages – Modularity of event types – Separation from inheritance – Reflection in the IDE Disadvantages – All events of a particular type go the same place class CoolEvent { information about the event } interface CoolListener { void coolHappened(CoolEvent e); } class DoCoolStuff { private Vector listeners; public void addCoolListener(CoolListener c) { listeners.add(c); } public void remCoolListener(CoolListener c) { listeners.remove(c); } protected void coolHappened(CoolEvent e) { for (CoolListener c: listeners) { c.coolHappened(e); } }

class ScrollBar extends Widget { private Vector listeners; public void addScrollListener(ScrollListener c) { listeners.add(c); } public void remScrollListener(ScrollListener c) { listeners.remove(c); } protected void scrollHappened(ScrollEvent e) { for (ScrollListener c: listeners) { c.scrollHappened(e); } } class Browser extends Widget implements ScrollListener { public void scrollHappened(ScrollEvent e) { if ( e.isVertical() ) scroll vertical; else scroll horizontal; } class Firefox { public void main(String args[]) { hScroll=new ScrollBar(); vScroll=new ScrollBar(); browse = new Browser(); hScroll.addScrollListener(browse); vScroll.addScrollListener(browse); }

Delegates public delegate void coolEventHandler(CoolEvent e) public class DoCoolStuff { public coolEventHandler handler; public void processMouseEvent(Event e) { handler(new CoolEvent() ); } public class BunchOfCoolness { public BunchOfCoolness() { DoCoolStuff cool1; cool1.handler = catch1; DoCoolStuff cool2; coo12.handler=catch2; } private void catch2(CoolEvent e) { } private void catch1(CoolEvent e) { } }

public delegate ScrollHandler(ScrollEvent); class ScrollBar extends Widget { public ScrollHandler scrollEvent; }

public delegate ScrollHandler(ScrollEvent); class ScrollBar extends Widget { public ScrollHandler scrollEvent; } class Browser extends Widget implements ScrollListener { public void scrollVertical(ScrollEvent e) { … } public void scrollHorizontal(ScrollEvent e) { … } }

public delegate ScrollHandler(ScrollEvent); class ScrollBar extends Widget { public ScrollHandler scrollEvent; } class Browser extends Widget implements ScrollListener { public void scrollVertical(ScrollEvent e) { … } public void scrollHorizontal(ScrollEvent e) { … } } class Firefox { public void main(String args[]) { hScroll=new ScrollBar(); vScroll=new ScrollBar(); browse = new Browser(); hScroll.scrollEvent = browse.scrollHorizontal; vScroll.scrollEvent = browse.scrollVertical; }

Delegates Advantages – Each event targeted – Some IDE help Disadvantages – ? public delegate void coolEventHandler(CoolEvent e) public class DoCoolStuff { public coolEventHandler handler; public void processMouseEvent(Event e) { handler(new CoolEvent() ); } public class BunchOfCoolness { public BunchOfCoolness() { DoCoolStuff cool1; cool1.handler = catch1; DoCoolStuff cool2; coo12.handler=catch2; } private void catch2(CoolEvent e) { } private void catch1(CoolEvent e) { } }

Interpretive Language … – eval(onclick) – Variable bindings

Anonymous Functions … – Variables where function is created – onclick(X,Y) somewhere inside of

Event Handling Event Queue and switch on event type Event Tables Class Inheritance Listeners Delegates