James Tam An introduction into HCI: Task-Centered System Design An Introduction To Graphical User Interfaces The event-driven model Building a simple.

Slides:



Advertisements
Similar presentations
Event handling and listeners What is an event? user actions and context event sources and listeners Why should my programs be event- driven? User interaction.
Advertisements

Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
James Tam An Introduction To Graphical User Interfaces The event-driven model Building simple graphical interfaces in Java.
Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
Event Handling Events and Listeners Timers and Animation.
Lecture 19 Graphics User Interfaces (GUIs)
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Object-Oriented Programming (Java), Unit 18 Kirk Scott 1.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Event Handling Mohanraj S AP / IT Angel College of Engg & Tech.,
Object-Oriented Programming (Java), Unit 18 Kirk Scott 1.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Layout Managers Arranges and lays out the GUI components on a container.
Event Driven Programming. Event-driven Programming In the early days of computing communication with the outside world was accomplished using a technique.
Pravin Yannawar, DOCS, NMU Jalgaon. Basic Java : Event handling in AWT and Swing 2 Objectives of This Session Explain the Event handling mechanism & demonstrate.
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.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Introduction to Java Programming
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Anonymous Classes An anonymous class is a local class that does not have a name. An anonymous class allows an object to be created using an expression.
A simple swing example GETTING STARTED WITH WIND CHILL.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
A cannon game ?. Simple version angle from command line, one shot only Coordinate system is “upside-down”: Use dy(int) method to transform y coordinate:
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
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.
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
A Quick Java Swing Tutorial
Lecture 15 Basic GUI programming
Modular Event Handling
GUIs and Events Rick Mercer.
CSC 205 Programming II Lecture 5 AWT - I.
CompSci 230 S Programming Techniques
Web Design & Development Lecture 11
A First Look at GUI Applications
Ellen Walker Hiram College
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Inner Classes 11/14/ Dec-04 inner_classes.ppt.
Constructors, GUI’s(Using Swing) and ActionListner
Tonga Institute of Higher Education
CiS 260: App Dev I Chapter 6: GUI and OOD.
GUI building with the AWT
Inner Classes.
Presentation transcript:

James Tam An introduction into HCI: Task-Centered System Design An Introduction To Graphical User Interfaces The event-driven model Building a simple graphical interface in Java

James Tam An introduction to graphical user interfaces in Java Traditional Software Program control is largely determined by the program through a series of statements. Start “Closed for the weekend” End If (day = SAT) OR (day = SUN) else

James Tam An introduction to graphical user interfaces in Java Traditional Software Program control is largely determined by the program through a series of statements. Start “Enter password” Input The program controls execution

James Tam An introduction to graphical user interfaces in Java Event-Driven Software RAM OS Program Current point of execution Program control can also be determined by events

James Tam An introduction to graphical user interfaces in Java Event-Driven Software RAM OS Program Current point of execution New point of execution (to handle the key press) Program control can also be determined by events

James Tam An introduction to graphical user interfaces in Java Characteristics Of Event Driven Software Program control can be determined by events as well standard program control statements The typical source of these events is the user These events can occur at any time

James Tam An introduction to graphical user interfaces in Java Onscreen Objects Can Trigger Events Graphical objects can be manipulated by the user to trigger events. Each object can have 0, 1 or many events that can be triggered.

James Tam An introduction to graphical user interfaces in Java Steps In The Event Model 1)The graphical component must register all interested event listeners. 2)The user triggers an event by manipulating that component 3)The component sends a message to all listeners of that event 4)The event listener provides code to handle the event

James Tam An introduction to graphical user interfaces in Java 1. The Graphical Component Must Register All Interested Event Listeners. Button (component) Class MyListener extends ActionListener { } … b.addActionListener()

James Tam An introduction to graphical user interfaces in Java 2. The User Triggers An Event By Manipulating That Component

James Tam An introduction to graphical user interfaces in Java 3. The Component Sends A Message To All Registered Listeners For That Event class MyListener extends ActionListener { public void actionPerformed (ActionEvent e) { }

James Tam An introduction to graphical user interfaces in Java 3. The Component Sends A Message To All Registered Listeners For That Event class MyListener extends ActionListener { public void actionPerformed (ActionEvent e) { button.setText(“Stop pressing me”); }

James Tam An introduction to graphical user interfaces in Java 4. The Event Listener Provides Code To Handle The Event class MyListener extends ActionListener { public void actionPerformed (ActionEvent e) { button.setText(“Stop pressing me”); }

James Tam An introduction to graphical user interfaces in Java Building A Simple GUI This example can be found in the directory: /home/profs/tamj/233/examples/GUIs

James Tam An introduction to graphical user interfaces in Java The Driver Class import java.awt.*; import java.awt.event.*; public class Driver { public static void main(String[] args) { Frame f = new Frame (); Panel p = new Panel (); f.add(p); Button makePopup = new Button ("Popup"); Button goesInvisible = new Button("Press me"); Button quitProgram = new Button ("Quit"); MyListener simpleListener = new MyListener ();

James Tam An introduction to graphical user interfaces in Java The Driver Class (2) // Para1 = x coordinate, Para2 = y coordinate, Para3 = width, Para4 = height f.setBounds(100,200,300,200); p.add(goesInvisible); p.add(makePopup); p.add(quitProgram); // Register simpleListener as a listener to when the buttons get pressed goesInvisible.addActionListener(simpleListener); makePopup.addActionListener(simpleListener); quitProgram.addActionListener(simpleListener); // Make the frame visible f.show(); }

James Tam An introduction to graphical user interfaces in Java Class MyListener import java.awt.*; import java.awt.event.*; public class MyListener implements java.awt.event.ActionListener { public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); if (s.equals("Popup")) { Frame f = new Frame ("Popup window"); f.setBounds(0,0,200,100); f.show(); for (int i = 0; i < ; i++); f.setTitle("Going away soon"); for (int i = 0; i < ; i++); f.setVisible(false); }

James Tam An introduction to graphical user interfaces in Java Class MyListener else if (s.equals("Press me")) { Button b = (Button) e.getSource(); b.setVisible(false); } else if (s.equals("Quit")) { System.exit(0); }

James Tam An introduction to graphical user interfaces in Java Summary You should now know: The difference between traditional and event driven software How event-driven software works A simple graphical interface example