Events. Dispatch, event-to-code binding. Review: Events Defined 1/17/2014. occurrence.

Size: px
Start display at page:

Download "Events. Dispatch, event-to-code binding. Review: Events Defined 1/17/2014. occurrence."

Transcription

1 Events Dispatch, event-to-code binding Review: Events Defined 1. An observable occurrence, phenomenon, or an extraordinary occurrence. 2. A message to notify an application that something happened. Examples: Keyboard (key press, key release) Pointer events (button press, button release, motion) Window crossing (mouse enters, leaves) Input focus (gained, lost) Window events (exposure, destroy, minimize) Timer events 2 1

2 Review: Event Dispatch Which part of the interface should receive the event? How do we get the correct code to execute in response to an event? Questions: - Which window? Which widget? Positional dispatch Bottom-up dispatch Top-down dispatch Focus dispatch (and after dispatch, how do we bind the event with code?) 4 Lightweight vs. Heavyweight Widgets Lightweight widgets - BWS/OS provides a top-level window - Widget toolkit draws its own widgets and is responsible for mapping events to their corresponding widgets - Examples: Java Swing, JQuery UI, Windows WPF, WatGUI Heavyweight widgets - Each widget is its own window (where window is not just what we typically call a window every control is a window) - OS provides a hierarchical windowing system for all widgets - Widget toolkit wraps OS widgets for programming language - BWS can dispatch events to a specific widget - Examples: nested X Windows, Java s AWT, OS X Cocoa, standard HTML form widgets, Windows MFC 5 CS 349 S13 - Widgets 2

3 Window Dispatch with BWS 6 Positional Dispatch Strategy: send input to widget under mouse cursor Issue: many widgets can overlap, which one should receive the event? Two methods: - Bottom-up - Top-down 7 3

4 Bottom-up Positional Dispatch Event is first routed to leaf node widget in the interactor tree corresponding to location of mouse cursor Leaf node has first opportunity to act on that event The leaf node widget can either: 1. process the event itself 2. pass the event to its parent (who can process it or send to its parent...) 8 Passing to Parent Why would a widget pass an event to its parent? - Example: A palette of colour swatches may implement the colours as buttons. But palette needs to track the currently selected colour. Easiest if the palette deals with the events. 9 4

5 Top-down Positional Dispatch Event is routed to widget in the highest-level node in the interactor tree that contains the mouse cursor - Can process the event itself - Can pass it on to a child component Key idea is that highest-level node has first chance at acting on the event Uses: - Can create policies that are enforced by parent For example, stopping events if all children are disabled - Supports relatively easy logging of events for later replay 10 Top-down vs. Bottom-up Dispatch To end-user, no difference in how interface behaves Just slightly different implementations disabled container widget policy 11 5

6 Positional Dispatch Limitations Positional dispatch can lead to odd behaviour: - Send keystrokes to scrollbar if mouse over the scrollbar? - Mouse drag starts in a scrollbar, but then moves outside the scrollbar: send the events to the adjacent widget? - Mouse press event in one button widget but release is in another: each button gets one of the events? Sometimes position isn t enough, also need to consider which widget is in focus 12 Focus Dispatch Events dispatched to widget that has focus, regardless of mouse cursor position Needed for all keyboard and some mouse events: - Click on text field, move cursor off, start typing (keyboard focus) - Mouse down on button, move off, mouse up (mouse focus) also called mouse capture Maximum one keyboard focus and one mouse focus Need to gain and lose focus at appropriate times - Transfer focus on mouse down - Transfer focus on a tab 13 6

7 Focus Dispatch Needs Positional Dispatch If a widget has focus, it should not receive every event: - mouse down on another suitable widget should change focus Often helpful to have an explicit focus manager in a container widget to manage which widget has the focus. 14 Accelerator Key Dispatch Keyboard events dispatched based on which keys are pressed Register special keyboard accelerators with specific commands - commands are often the target of menu item events The GUI toolkit intercepts accelerators and forwards to the appropriate command handler 15 7

8 Dispatch Summary Mouse-down events are almost always positional: dispatched to widget under cursor (top-down or bottom-up) Other mouse and keyboard events go to widget in focus 16 Event-to-Code Binding BWS and widget toolkit decide which widget event should be dispatched to Once the event arrives at the widget, the next step is to have application logic interpret the event Key question: How do we design our GUI architecture to enable application logic to interpret events once they ve arrived at the widget? Desiderata for design: - Easy to understand (clear connection between events and code) - Easy to implement (using a binding paradigm or API) - Easy to debug (how did this event get to this piece of code?) - Good performance 17 8

9 Event Loop and Switch Statement Binding (X11) All application events are consumed in one event loop Outer switch statement selects window and inner switch selects code to handle the event Used in Xlib, Apple System 7, and, until recently, Blender while( true ) { XNextEvent(display, &event); // wait for next event switch(event.type) { case Expose: //... handle expose event... cout << event.xexpose.count << endl; break; case ButtonPress: //... handle button press event... cout << event.xbutton.x << endl; break; WinowProc Binding (MS Windows) Each window registers a WindowProc function (Window Procedure) which is called each time an event is dispatched The WindowProc uses a switch statement to identify each event that it needs to handle. - There are over 100 standard events LRESULT CALLBACK WindowProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam) { switch (umsg) { case WM_SIZE: { int width = LOWORD(lParam); // low- order word. int height = HIWORD(lParam); // high- order word. // Respond to the message: OnSize(hwnd, (UINT)wParam, width, height); break; 19 9

10 Inheritance Binding (Java 1.0, NeXT, OSX) Event is dispatched to an Object-Oriented (OO) widget OO widget inherits from a base widget class with all event handling methods defined a priori - onmousepress, onmousemove, onkeypress, etc The widget overrides methods for events it wishes to handle e.g. Java 1.0, NeXT, OSX 23 public class MyMarvelousPanel extends JPanel { protected void processmousemotionevent(mouseevent e) { // only detects button state WHILE moving! if (e.getid() == MouseEvent.MOUSE_DRAGGED) colour = Color.RED; else colour = Color.GRAY; x = e.getx(); y = e.gety(); repaint(); 24 10

11 Inheritance Problems 1. Each widget handles its own events, or widget container has to check what widget the event is meant for 2. Multiple event types are processed through each event method: complex and error-prone (just a switch again) 3. No filtering of events: performance issues (e.g. with frequent events, like mouse move events) 4. It doesn t scale well: How to add new events? - e.g. penbuttonpress, touchgesture,. 5. Muddies separation between GUI and application logic: event handling application code is in inherited widget Take-home point: Use inheritance for extending class functionality, not for binding events 27 Event Interfaces Rather than subclass widget, define an interface for event handling Here, an interface refers to a set of function or method signatures for handling specific types of events For example, in Java, can define an interface for handling mouse events Can then create a class that implements that interface by implementing methods for handling these mouse events 28 11

12 Listener Interface Binding (Java) Widget object implements event listener interfaces - e.g. MouseListener, MouseMotionListener, KeyListener, When event is dispatched to widget, the relevant listener method is called - mousepressed, mousemoved, 29 public class MyAwesomePanel extends JPanel implements MouseMotionListener { MyAwesomePanel() { this.addmousemotionlistener(this); // add listener public void mousedragged(mouseevent e) { x = e.getx(); y = e.gety(); // Change state of app in some meaningful way repaint(); public void mousemoved(mouseevent e) { /* no- op */ 30 12

13 Interface Better, But Still Problems Improvements: - Each event types assigned to an event method - Events are filtered: only sent to object which implements interface - Easy to scale to new events, just add new interfaces e.g. PenInputListener, TouchGestureListener,. Problems: 1. Each widget handles its own events, or widget container has to check what widget the event is meant for 2. Muddies separation between GUI and application logic: event handling application code is in inherited widget 31 Listener Object Binding (Java 1.1) Widget object is associated with one or more event listener objects (which implement an event binding interface) - e.g. MouseListener, MouseMotionListener, KeyListener, When event is dispatched to a widget, the relevant listener object processes the event with implemented method: mousepressed, mousereleased, application logic and event handling are decoupled 32 13

14 MouseListener public class MyImportantPanel extends JPanel { ListenerEvents() { this.addmousemotionlistener(new MyPanelListener()); // inner class listener class MyPanelListener implements MouseMotionListener { public void mousedragged(mouseevent e) { x = e.getx(); y = e.gety(); // Make some meaningful change to app repaint(); public void mousemoved(mouseevent e) { /* no- op */ 33 Listener Adapter Pattern Many listener interfaces have only a single method - e.g. ActionListener has only actionperformed Other listener interfaces have several methods - e.g. WindowListener has 7 methods, including windowactivated, windowclosed, windowclosing, Typically interested in only a few of these methods. Leads to lots of boilerplate code with no-op methods, e.g. void windowclosed(windowevent e) { Each listener with multiple methods has an Adapter class with no-op methods. Simply extend the adapter, overriding only the methods of interest

15 MouseMotionAdapter public class AdapterEvents extends JPanel { AdapterEvents() { this.addmousemotionlistener(new MyListener()); class MyListener extends MouseMotionAdapter { public void mousedragged(mouseevent e) { x = e.getx(); y = e.gety(); // Do something meaningful here repaint(); 35 WatGUI Toolkit WatGUI s Timer class has hooks for a TimerListener object TimerListener is equivalent to an interface: Defines an interface for a class, but doesn t implement anything meaningful Any object derived from TimerListener will be notified whenever the Timer s predesignated time has elapsed StopWatch derived from TimerListener 36 15

16 Delegate Binding (.NET) Interface architecture can be a bit heavyweight Can instead have something closer to a simple function callback (a function called when a specific event occurs) Delegates in Microsoft s.net are like a C/C++ function pointer for methods, but they: - Are object oriented - Are completely type checked - Are more secure - Support multicasting (able to point to more than one method) Using delegates is a way to broadcast and subscribe to events.net has special delegates called events 37 Using Delegates 1. Declare a delegate using a method signature public delegate void Del(string message); 2. Declare a delegate object Del handler; 3. Instantiate the delegate with a method // method to delegate (in MyClass) public static void MyMethod(string message) { System.Console.WriteLine(message); handler = myclassobject.mymethod; 4. Invoke the delegate handler( Hello World ); 38 16

17 Multicasting Instantiate more than one method for a delegate object handler = MyMethod1 + MyMethod2; handler += MyMethod3; Invoke the delegate, calling all the methods handler( Hello World ); Remove method from a delegate object handler - = MyMethod1; What about this? handler = MyMethod4; 39 Events in.net Events are a delegate with restricted access - (or Events are implemented with a delegate) Declare an event object instead of a delegate object: public delegate void Del(string message); event Del handler; event keyword allows enclosing class to use delegate as normal, but outside code can only use the -= and += features of the delegate Gives enclosing class exclusive control over the delegate Outside code can t wipe out delegate list, can t do this: - handler = MyMethod4; 40 17

18 WatGUI Toolkit Has event types defined (e.g., MouseEvent), but method for responding to events is not defined in architecture For the curious: The Scheme interpreter actually supports a form of delegates for responding to - You register a Scheme function with a SchemeComponent to be notified when a particular event has occurred - But outside scope of this class (translation: You don t need to know this) - Talk to Professor Terry if interested in learning more 41 OS X Uses Inheritance and Delegate Binding Inheritance Binding - When an NSWindow object receives a mouse-down event, it asks the widget (an NSView object) under the event if it wants to handle the event (if that NSView s acceptsfirstresponder method returns YES). If so, it will call the method (a message ) from NSView for the event, such as mousedragged Delegate Binding 44 18

19 Events for High Frequency Input Pen and touch input can generate many events very quickly - pen motion input can be 125Hz - multitouch hardware can generate many simultaneous contactmove events for all fingers which are touching - pen sensor is much higher resolution than display Not all events guaranteed to be delivered individually - All pendown and penup, but may skip some penmove events - Event object includes array of skipped penmove positions - Android does this for touch input For things like pen input, will use other methods to grab these events because of their high rate of generation 49 19

Event Binding. Different Approaches Global Hooks. 2.5 Event Binding 1

Event Binding. Different Approaches Global Hooks. 2.5 Event Binding 1 Event Binding Different Approaches Global Hooks 2.5 Event Binding 1 Event Dispatch vs. Event Binddling Event Dispatch phase addresses: - Which window receives an event? - Which widget processes it? Positional

More information

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. 2.4 Event Dispatch 1

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. 2.4 Event Dispatch 1 Event Dispatch Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch 2.4 Event Dispatch 1 Event Architecture A pipeline: - Capture and Queue low-level hardware events - Dispatch

More information

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. Event Architecture. A pipeline: Event Capture

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. Event Architecture. A pipeline: Event Capture Event Dispatch Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch 2.4 Event Dispatch 1 Event Architecture A pipeline: - Capture and Queue low-level hardware events - Dispatch

More information

Event Dispatch. Dispatching events to windows and widgets.

Event Dispatch. Dispatching events to windows and widgets. Event Dispatch Dispatching events to windows and widgets. Review: Event Architecture 2 Event capture, processing and dispatch. Event Capture Hardware events (interrupts) Event Dispatch Software events

More information

Event Dispatch. Review: Events

Event Dispatch. Review: Events Event Dispatch 1 Review: Events Event: noun: a thing that happens, especially one of importance. Example: the media focused on events in Egypt Event: a structure used to notify an application of an event

More information

Widget Toolkits CS MVC

Widget Toolkits CS MVC Widget Toolkits 1 CS349 -- MVC Widget toolkits Also called widget libraries or GUI toolkits or GUI APIs Software bundled with a window manager, operating system, development language, hardware platform

More information

Widget. Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down

Widget. Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down Widgets Jeff Avery Widget Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down menus, spinners, file dialog boxes, etc are

More information

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1 Widgets Widgets Widget Toolkits 2.3 Widgets 1 User Interface Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, drop-down menus, spinners, file dialog boxes,

More information

Widgets. Widgets Widget Toolkits. User Interface Widget

Widgets. Widgets Widget Toolkits. User Interface Widget Widgets Widgets Widget Toolkits 2.3 Widgets 1 User Interface Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, drop-down menus, spinners, file dialog boxes,

More information

Windows and Events. created originally by Brian Bailey

Windows and Events. created originally by Brian Bailey Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating

More information

Event Driven Programming

Event Driven Programming Event Driven Programming 1. Objectives... 2 2. Definitions... 2 3. Event-Driven Style of Programming... 2 4. Event Polling Model... 3 5. Java's Event Delegation Model... 5 6. How to Implement an Event

More information

The AWT Event Model 9

The AWT Event Model 9 The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow

More information

Lecture 19 GUI Events

Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous inner classes Proper interaction

More information

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo Widgets Overview Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, progress

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Spring 2017 GUI Event-Driven Programming 1 The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

CSE 331 Software Design and Implementation. Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression testing

More information

GUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1)

GUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1) Objectives Write code to handle events that occur in a GUI 11 GUI Event Handling Describe the concept of adapter classes, including how and when to use them Determine the user action that originated the

More information

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by

More information

CS11 Java. Fall Lecture 4

CS11 Java. Fall Lecture 4 CS11 Java Fall 2006-2007 Lecture 4 Today s Topics Interfaces The Swing API Event Handlers Inner Classes Arrays Java Interfaces Classes can only have one parent class No multiple inheritance in Java! By

More information

GUI Event Handlers (Part I)

GUI Event Handlers (Part I) GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event

More information

UI Software Organization

UI Software Organization UI Software Organization The user interface From previous class: Generally want to think of the UI as only one component of the system Deals with the user Separate from the functional core (AKA, the app

More information

CS11 Java. Fall Lecture 3

CS11 Java. Fall Lecture 3 CS11 Java Fall 2014-2015 Lecture 3 Today s Topics! Class inheritance! Abstract classes! Polymorphism! Introduction to Swing API and event-handling! Nested and inner classes Class Inheritance! A third of

More information

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example

More information

GUI Software Architecture

GUI Software Architecture GUI Software Architecture P2: Requirements Analysis User Analysis Task Analysis Problem Scenarios Usability Criteria Scenario Your engineers just developed a new desktop computer. They give you the following

More information

AP Computer Science Unit 13. Still More Graphics and Animation.

AP Computer Science Unit 13. Still More Graphics and Animation. AP Computer Science Unit 13. Still More Graphics and Animation. In this unit you ll learn about the following: Mouse Motion Listener Suggestions for designing better graphical programs Simple game with

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7 PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,

More information

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing. COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization

More information

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

GUI Components: Part 1

GUI Components: Part 1 1 2 11 GUI Components: Part 1 Do you think I can listen all day to such stuff? Lewis Carroll Even a minor event in the life of a child is an event of that child s world and thus a world event. Gaston Bachelard

More information

Events. Events and the Event Loop Animation Double Buffering. 1.5 Events 1

Events. Events and the Event Loop Animation Double Buffering. 1.5 Events 1 Events Events and the Event Loop Animation Double Buffering 1.5 Events 1 Human vs. System User Interactive System perceive present seconds milliseconds or faster express translate 1.5 Events 2 Event Driven

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

CS 116x Winter 2015 Craig S. Kaplan. Module 03 Graphical User Interfaces. Topics

CS 116x Winter 2015 Craig S. Kaplan. Module 03 Graphical User Interfaces. Topics CS 116x Winter 2015 Craig S. Kaplan Module 03 Graphical User Interfaces Topics The model-view-controller paradigm Direct manipulation User interface toolkits Building interfaces with ControlP5 Readings

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014 Introduction to GUIs Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2014 Slides copyright 2014 by Jonathan Aldrich, Charlie Garrod, Christian

More information

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

We will talk about Alt-Tab from the usability perspective. Think about: - Is it learnable? - Is it efficient? - What about errors and safety?

We will talk about Alt-Tab from the usability perspective. Think about: - Is it learnable? - Is it efficient? - What about errors and safety? 1 This lecture s candidate for the Hall of Fame & Shame is the Alt-Tab window switching interface in Microsoft Windows. This interface has been copied by a number of desktop systems, including KDE, Gnome,

More information

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features: Lecture 28 Exceptions and Inner Classes Goals We are going to talk in more detail about two advanced Java features: Exceptions supply Java s error handling mechanism. Inner classes ease the overhead of

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

Cheng, CSE870. More Frameworks. Overview. Recap on OOP. Acknowledgements:

Cheng, CSE870. More Frameworks. Overview. Recap on OOP. Acknowledgements: More Frameworks Acknowledgements: K. Stirewalt. Johnson, B. Foote Johnson, Fayad, Schmidt Overview eview of object-oriented programming (OOP) principles. Intro to OO frameworks: o Key characteristics.

More information

CS 160: Interactive Programming

CS 160: Interactive Programming CS 160: Interactive Programming Professor John Canny 3/8/2006 1 Outline Callbacks and Delegates Multi-threaded programming Model-view controller 3/8/2006 2 Callbacks Your code Myclass data method1 method2

More information

BASICS OF GRAPHICAL APPS

BASICS OF GRAPHICAL APPS CSC 2014 Java Bootcamp Lecture 7 GUI Design BASICS OF GRAPHICAL APPS 2 Graphical Applications So far we ve focused on command-line applications, which interact with the user using simple text prompts In

More information

Packages: Putting Classes Together

Packages: Putting Classes Together Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic

More information

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety(); 11 The Jav aawt Part I: Mouse Events 11.1 public void mouseentered (MouseEvent e) setminute(getminute()+increment); 53 public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public

More information

CSC207 Week 4. Larry Zhang

CSC207 Week 4. Larry Zhang CSC207 Week 4 Larry Zhang 1 Logistics A1 Part 1, read Arnold s emails. Follow the submission schedule. Read the Q&A session in the handout. Ask questions on the discussion board. Submit on time! Don t

More information

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI 51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface

More information

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to the JAVA UI classes Advanced HCI IAT351 Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Class 27: Nested Classes and an Introduction to Trees

Class 27: Nested Classes and an Introduction to Trees Introduction to Computation and Problem Solving Class 27: Nested Classes and an Introduction to Trees Prof. Steven R. Lerman and Dr. V. Judson Harward Goals To explain in more detail the different types

More information

MOBILE COMPUTING 1/20/18. How many of you. CSE 40814/60814 Spring have implemented a command-line user interface?

MOBILE COMPUTING 1/20/18. How many of you. CSE 40814/60814 Spring have implemented a command-line user interface? MOBILE COMPUTING CSE 40814/60814 Spring 2018 How many of you have implemented a command-line user interface? How many of you have implemented a graphical user interface? HTML/CSS Java Swing.NET Framework

More information

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA Assignment No. 4 SD Module-1 Advanced JAVA R C (4) V T Total (10) Dated Sign Title: Transform the above system from command line system to GUI based application Problem Definition: Write a Java program

More information

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4. 1 - What if the main method is declared as private? 1. The program does not compile 2. The program compiles but does not run 3. The program compiles and runs properly ( From Lectuer # 2) 4. The program

More information

SD Module-1 Advanced JAVA. Assignment No. 4

SD Module-1 Advanced JAVA. Assignment No. 4 SD Module-1 Advanced JAVA Assignment No. 4 Title :- Transform the above system from command line system to GUI based application Problem Definition: Write a Java program with the help of GUI based Application

More information

Java for Interfaces and Networks (DT3010, HT10)

Java for Interfaces and Networks (DT3010, HT10) Java for Interfaces and Networks (DT3010, HT10) Mouse Events, Timers, Serialization Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 13, 2017 Model / View / Controller Chapter 31 How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal

More information

Advanced Java Programming (17625) Event Handling. 20 Marks

Advanced Java Programming (17625) Event Handling. 20 Marks Advanced Java Programming (17625) Event Handling 20 Marks Specific Objectives To write event driven programs using the delegation event model. To write programs using adapter classes & the inner classes.

More information

Class 16: The Swing Event Model

Class 16: The Swing Event Model Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present

More information

GUI in Java TalentHome Solutions

GUI in Java TalentHome Solutions GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 36 November 30, 2018 Mushroom of Doom Model / View / Controller Chapter 31 Announcements Game Project Complete Code Due: Monday, December 10th NO LATE

More information

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently. UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING 1. What are Threads? A thread is a single path of execution of code in a program. A Multithreaded program contains two or more parts that can run concurrently.

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT-V TWO MARKS QUESTION & ANSWER 1. What is the difference between the Font and FontMetrics class? Font class is used to set or retrieve the screen fonts.the Font class maps the characters of the language

More information

Building custom components IAT351

Building custom components IAT351 Building custom components IAT351 Week 1 Lecture 1 9.05.2012 Lyn Bartram lyn@sfu.ca Today Review assignment issues New submission method Object oriented design How to extend Java and how to scope Final

More information

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology: Inheritance 1 Inheritance One class inherits from another if it describes a specialized subset of objects Terminology: the class that inherits is called a child class or subclass the class that is inherited

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

Exploring Processing

Exploring Processing Exploring Processing What is Processing? Easy-to-use programming environment Let s you edit, run, save, share all in one application Designed to support interactive, visual applications Something we ve

More information

Lecture 9: UI Software Architecture. Fall UI Design and Implementation 1

Lecture 9: UI Software Architecture. Fall UI Design and Implementation 1 Lecture 9: UI Software Architecture Fall 2003 6.893 UI Design and Implementation 1 UI Hall of Fame or Shame? Source: Interface Hall of Shame Fall 2003 6.893 UI Design and Implementation 2 Today s hall

More information

Come & Join Us at VUSTUDENTS.net

Come & Join Us at VUSTUDENTS.net Come & Join Us at VUSTUDENTS.net For Assignment Solution, GDB, Online Quizzes, Helping Study material, Past Solved Papers, Solved MCQs, Current Papers, E-Books & more. Go to http://www.vustudents.net and

More information

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms. Java GUI Windows Events Drawing 1 Java GUI Toolkits Toolkit AWT Description Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information

Programming Language Concepts: Lecture 8

Programming Language Concepts: Lecture 8 Programming Language Concepts: Lecture 8 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 8, 11 February 2009 GUIs and event

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Java Graphics and GUIs (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Review: how to create

More information

Lab 10: Inheritance (I)

Lab 10: Inheritance (I) CS2370.03 Java Programming Spring 2005 Dr. Zhizhang Shen Background Lab 10: Inheritance (I) In this lab, we will try to understand the concept of inheritance, and its relation to polymorphism, better;

More information

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 P a g e 1 CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 Q1 Describe some Characteristics/Advantages of Java Language? (P#12, 13, 14) 1. Java

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 November 30 th 2015 Design PaBerns Model / View / Controller Chapter 31 Game project grading Game Design Proposal Milestone Due: (12 points) Tuesday

More information

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics Using Methods Methods that handle events Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Caveat The term function is used in Processing e.g. line(),

More information

CS2110 Fall 2015 Assignment A5: Treemaps 1

CS2110 Fall 2015 Assignment A5: Treemaps 1 CS2110 Fall 2015 Assignment A5: Treemaps 1 1. Introduction Assignment 5: Treemaps We continue our study of recursive algorithms and also gain familiarity with building graphical user interfaces (GUIs)

More information

Fall UI Design and Implementation 1

Fall UI Design and Implementation 1 Fall 2005 6.831 UI Design and Implementation 1 1 Suggested by Daniel Swanton Fall 2005 6.831 UI Design and Implementation 2 2 Suggested by Robert Kwok Fall 2005 6.831 UI Design and Implementation 3 3 Input

More information

Which of the following syntax used to attach an input stream to console?

Which of the following syntax used to attach an input stream to console? Which of the following syntax used to attach an input stream to console? FileReader fr = new FileReader( input.txt ); FileReader fr = new FileReader(FileDescriptor.in); FileReader fr = new FileReader(FileDescriptor);

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 15, 2013 Swing III: OO Design, Mouse InteracGon Announcements HW10: Game Project is out, due Tuesday, April 23 rd at midnight If you want

More information

CS 106A, Lecture 14 Events and Instance Variables

CS 106A, Lecture 14 Events and Instance Variables CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons

More information

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

CS 4300 Computer Graphics

CS 4300 Computer Graphics CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 8 September 22, 2011 GUIs GUIs in modern operating systems cross-platform GUI frameworks common GUI widgets event-driven programming Model-View-Controller

More information

Introduction to concurrency and GUIs

Introduction to concurrency and GUIs Principles of Software Construction: Objects, Design, and Concurrency Part 2: Designing (Sub)systems Introduction to concurrency and GUIs Charlie Garrod Bogdan Vasilescu School of Computer Science 1 Administrivia

More information

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class. Q1. If you add a component to the CENTER of a border layout, which directions will the component stretch? A1. The component will stretch both horizontally and vertically. It will occupy the whole space

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 2011 Extending JFrame Dialog boxes Overview Ge

More information

CS 106A, Lecture 14 Events and Instance Variables

CS 106A, Lecture 14 Events and Instance Variables CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons

More information

Chapter 1 GUI Applications

Chapter 1 GUI Applications Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations

More information

Java: Graphical User Interfaces (GUI)

Java: Graphical User Interfaces (GUI) Chair of Software Engineering Carlo A. Furia, Marco Piccioni, and Bertrand Meyer Java: Graphical User Interfaces (GUI) With material from Christoph Angerer The essence of the Java Graphics API Application

More information

Lecture 1 Introduction to Android. App Development for Mobile Devices. App Development for Mobile Devices. Announcement.

Lecture 1 Introduction to Android. App Development for Mobile Devices. App Development for Mobile Devices. Announcement. CSCE 315: Android Lectures (1/2) Dr. Jaerock Kwon App Development for Mobile Devices Jaerock Kwon, Ph.D. Assistant Professor in Computer Engineering App Development for Mobile Devices Jaerock Kwon, Ph.D.

More information

Interactor Tree. Edith Law & Mike Terry

Interactor Tree. Edith Law & Mike Terry Interactor Tree Edith Law & Mike Terry Today s YouTube Break https://www.youtube.com/watch?v=mqqo-iog4qw Routing Events to Widgets Say I click on the CS349 button, which produces a mouse event that is

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications

More information

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/uiswing/toc.html http://www.unix.org.ua/orelly/java-ent/jfc/

More information

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic

More information

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm } Abstract Window Toolkit Delegates creation and

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Ge?ng user input Overview Displaying message or error Listening for

More information