CSSE221: Software Dev. Honors Day 9 Announcements Announcements HW3 passed back, follow link from HW3 to its solution. HW3 passed back, follow link from.

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

1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Graphic User Interfaces Layout Managers Event Handling.
Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
Event Handling Events and Listeners Timers and Animation.
CSSE221: Software Dev. Honors Day 10 Announcements Announcements Fifteen due Monday 11:59 pm. Monday will be a workday. Fifteen due Monday 11:59 pm. Monday.
Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
CSSE221: Software Dev. Honors Day 4 Pass in Runtime Assignment now to assistants Pass in Runtime Assignment now to assistants Announcements Announcements.
Event-Driven Programming
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions.
CSSE221: Software Dev. Honors Day 5 Announcements Announcements Homework 2 written portion due now Homework 2 written portion due now You survived the.
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.
CSSE221: Software Dev. Honors Day 7 Announcements Announcements HW2 and inheritance quiz returned now. HW2 and inheritance quiz returned now. Solutions.
Lecture 241 CS110 Lecture 25 Tuesday, May 4, 2004 Announcements –final exam Thursday, May 20, 8:00 AM McCormack, Floor 01, Room 0608 (easier than last.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
CSSE221: Software Dev. Honors Day 17 Announcements Announcements Fifteen and CarsTrucksTrains coming back Fifteen and CarsTrucksTrains coming back Note:
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
Programming Task: Task 1 Controlled Assessment Practice.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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,
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
CS Lecture 00 Swing overview and introduction Lynda Thomas
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
MSc Workshop - © S. Kamin, U.Reddy Lect 4 - Events - 1 Lecture 4 – Event Handling r Painting r Event types r Catching different event types.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
OOP (Java): GUI Intro/ OOP Objectives – –use an image viewer application to introduce Java's GUI features Semester 2,
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
For (int i = 1; i
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
UID – Event Handling and Listeners Boriana Koleva
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Lesson 6 Programming Techniques Event Handling /EvH/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
Object Oriented Programming.  Interface  Event Handling.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
CS Lecture 04 Mice Lynda Thomas
Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
Mouse Events GUI. Types of Events  Below, are some of the many kinds of events, swing components generate. Act causing EventListener Type User clicks.
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.
Event Handling CS 21a: Introduction to Computing I First Semester,
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.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CompSci 230 S Programming Techniques
A First Look at GUI Applications
Advanced User Interfaces
Quick intro to Event Driven Programming
Ellen Walker Hiram College
GUI Programming III: Events
Events, Event Handlers, and Threads
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

CSSE221: Software Dev. Honors Day 9 Announcements Announcements HW3 passed back, follow link from HW3 to its solution. HW3 passed back, follow link from HW3 to its solution. Questions on GUIs? Questions on GUIs? No baby yet… No baby yet…

Capsule Deliverables Please the quiz, key, and summary to me by 7:30 am on the day you are presenting. Please the quiz, key, and summary to me by 7:30 am on the day you are presenting. Send.doc files Send.doc files (If you get them to me by 3pm on a weekday before you present, I’ll still print them) (If you get them to me by 3pm on a weekday before you present, I’ll still print them) Lessons from week 1: Lessons from week 1: Nice research and summarization! Nice research and summarization! Proofread your stuff. Everyone else will see it. Proofread your stuff. Everyone else will see it. 1-page quizzes are good (or staple) 1-page quizzes are good (or staple) Summaries don’t have to be verbose, just dense with info. Summaries don’t have to be verbose, just dense with info.

This week: Fifteen assignment Monday: Monday: GUIs using Java’s Swing library GUIs using Java’s Swing library Tuesday: Tuesday: Fifteen specification Fifteen specification EventListeners: responding to user input EventListeners: responding to user input Intro to UML as a design tool Intro to UML as a design tool Time to work on project Time to work on project Thursday: Thursday: Anonymous classes (capsule) Anonymous classes (capsule) Function objects and comparators (capsule) Function objects and comparators (capsule)

“Fifteen” Questions on Specification?

Fifteen Teams beltonj1-fishmad bennetrn-leveyjr bennindp-speyerea crockeea-morrisps devorejd-priestjs lundgrpb-skilessa johnsoad-smithny sullivja-wentztj mcginnda behlinmc-bennetdj clutecc-dovalojd gatesds heinma1-hulettbh johnsoac-rubinza kruthar-richarme millerbe-eckertwm mosttw-reillytm nibertjw-stokese Repos is csse If solo, use your personal repos. Discuss how to pair-program

Event-driven Programming: What? We want our program to respond to events We want our program to respond to events Mouse motion, mouse clicks, button presses, menu selections, … Mouse motion, mouse clicks, button presses, menu selections, … The Java window manager generates a huge number of events The Java window manager generates a huge number of events Whenever any of these happen Whenever any of these happen We need to listen for specific events We need to listen for specific events class Foo implements MouseListener { … }

Event-driven Programming: How? Implement the BlahListener interface Implement the BlahListener interface class Foo implements MouseMotionListener { … // We promise to implement these. void mouseDragged(MouseEvent e) { mouseDraggedMouseEventmouseDraggedMouseEvent System.out.println(“Hey, stop pulling me!”); } void mouseMoved(MouseEvent e) { System.out.println(“The mouse is moving!”); mouseMovedMouseEventmouseMovedMouseEvent System.out.println(e.getX() + “ “ + e.getY()); }}

Event-driven Programming: Which? Interface, that is… MouseMotionListener MouseMotionListener For receiving mouse motion events (movement and dragging) on a component. For receiving mouse motion events (movement and dragging) on a component. MouseListener MouseListener For clicks and other mouse events (click and double-click, mouse enters component) For clicks and other mouse events (click and double-click, mouse enters component) ActionListener ActionListener For component-defined actions (such as pressing a button) For component-defined actions (such as pressing a button) KeyboardListener KeyboardListener ChangeListener ChangeListener For components in which we only care about change (like sliders) For components in which we only care about change (like sliders) See the API spec. for which methods you need to write

Listeners Need 3 things! Need 3 things! 1. Responder implements ActionListener interface 2. This means it implements actionPerformed method: public void actionPerformed(ActionEvent e) { // what happens when button is pressed } 3. The responder must add the listener: Say a frame has a button. this.button.addActionListener(this); Listens Responds (this is the frame, but could be a panel or even the button itself)

E.g. Button in a Panel Button is the event source Button is the event source Panel has to respond to the event and therefore must listen for events. Panel has to respond to the event and therefore must listen for events. public TopPanel extends JPanel implements ActionListener { private JButton changeColor; private JButton changeColor; … public TopPanel(){ public TopPanel(){ this.changeColor = new JButton(“Click to change color”); this.changeColor = new JButton(“Click to change color”); this.changeColor.addActionListener(this); //Add the listener to the source this.changeColor.addActionListener(this); //Add the listener to the source this.add(changeColor); this.add(changeColor); } public void actionPerformed(ActionEvent e){ public void actionPerformed(ActionEvent e){ //Change the background color of the panel //Change the background color of the panel }}

Do I have to write a whole separate class in its own file, just for an actionPerformed method? No! You could use an anonymous class or a function object No! You could use an anonymous class or a function object More on those next class More on those next class Funny that that’s the ordering of topics… Funny that that’s the ordering of topics…

Finish demo together Draw the UML for all classes so far Draw the UML for all classes so far Add the listeners. Add the listeners. What other connections do I need? What other connections do I need? Look at its Iterative Enhancement Plan together Look at its Iterative Enhancement Plan together Code Code Sliders are similar, I used the Java Swing Tutorial for some ideas. Sliders are similar, I used the Java Swing Tutorial for some ideas.

Start Fifteen Spec now You need to do 2 things before you start coding: You need to do 2 things before you start coding: Show us your UML Show us your UML Show us your Iterative Enhancement Plan Show us your Iterative Enhancement Plan

UML ideas List of components List of components For each component For each component Extends a class? Extends a class? Implements interfaces? Implements interfaces? Creates instances of other components? Creates instances of other components? Has instances of other components? Has instances of other components? For which objects can I use the default Java version and which do I need to extend? For which objects can I use the default Java version and which do I need to extend? Frames, panels: extend Frames, panels: extend Text boxes: use Java’s Text boxes: use Java’s Buttons: it depends Buttons: it depends Do now with another team (so groups of 4) on a whiteboard. Do now with another team (so groups of 4) on a whiteboard.

Iterative enhancement plan Such a plan ensures that you always have code that works Such a plan ensures that you always have code that works Each stage must be testable by running the application Each stage must be testable by running the application No looking at code! No looking at code! So “implement the Dud class” is NOT part of an iterative enhancement plan So “implement the Dud class” is NOT part of an iterative enhancement plan It is OK for some stages to include throw-away code It is OK for some stages to include throw-away code The stages should be about the same size/difficulty The stages should be about the same size/difficulty Iterative enhancement plan: A series of stages (and substages) by which to develop the application, with each stage testable by running the application