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

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

  • View
    228

  • Download
    0

Embed Size (px)

Citation preview

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

CSSE221: Software Dev. Honors CSSE221: Software Dev. Honors Day 9Day 9 AnnouncementsAnnouncements

HW3 passed back, follow link from HW3 HW3 passed back, follow link from HW3 to its solution.to its solution.

Questions on GUIs?Questions on GUIs?

No baby yet…No baby yet…

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

Capsule DeliverablesCapsule Deliverables Please email the quiz, key, and summary to Please email the quiz, key, and summary to

me by 7:30 am on the day you are presenting.me by 7:30 am on the day you are presenting. Send .doc filesSend .doc files (If you get them to me by 3pm on a weekday (If you get them to me by 3pm on a weekday

before you present, I’ll still print them)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 Summaries don’t have to be verbose, just dense

with info.with info.

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

This week: Fifteen This week: Fifteen assignmentassignment

Monday:Monday: GUIs using Java’s Swing library GUIs using Java’s Swing library

Tuesday:Tuesday: Fifteen specificationFifteen specification EventListeners: responding to user inputEventListeners: responding to user input Intro to UML as a Intro to UML as a designdesign tool tool Time to work on projectTime to work on project

Thursday:Thursday: Anonymous classes (capsule)Anonymous classes (capsule) Function objects and comparators (capsule)Function objects and comparators (capsule)

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

““Fifteen”Fifteen”

Questions on Questions on Specification?Specification?

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

Fifteen TeamsFifteen 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 csse221-200810-<usr1>-<usr2>. If solo, use your personal repos.

Discuss how to pair-program

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

Event-driven Programming: Event-driven Programming: What?What?

We want our program to We want our program to respond to respond to eventsevents Mouse motion, mouse Mouse motion, mouse

clicks, button presses, clicks, button presses, menu selections, …menu selections, …

The Java window The Java window manager generates a manager generates a huge number of eventshuge number of events Whenever any of these Whenever any of these

happenhappen We need to listen for We need to listen for

specific eventsspecific events

class Foo implements MouseListener {

}

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

Event-driven Programming: Event-driven Programming: How?How?

Implement the Implement the BlahBlahListener Listener interfaceinterface

class Foo implements MouseMotionListener {class Foo implements MouseMotionListener {……// We promise to implement these.// We promise to implement these.void void mouseDraggedmouseDragged((MouseEventMouseEvent e) {  e) { System.out.println(“Hey, stop pulling me!”);System.out.println(“Hey, stop pulling me!”);

}}void void mouseMovedmouseMoved((MouseEventMouseEvent e) {  e) { System.out.println(“The mouse is moving!”);System.out.println(“The mouse is moving!”);System.out.println(e.getX() + “ “ + e.getY());System.out.println(e.getX() + “ “ + e.getY());

}}}}

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

Event-driven Programming: Event-driven Programming: Which? Which?

Interface, that is…Interface, that is… MouseMotionListenerMouseMotionListener

For receiving mouse motion events (movement and For receiving mouse motion events (movement and dragging) on a component. dragging) on a component.

MouseListenerMouseListener For clicks and other mouse events (click and double-For clicks and other mouse events (click and double-

click, mouse enters component)click, mouse enters component)

ActionListenerActionListener For component-defined actions (such as pressing a For component-defined actions (such as pressing a

button)button)

KeyboardListenerKeyboardListener

ChangeListenerChangeListener For components in which we only care about change (like For components in which we only care about change (like

sliders)sliders)

See the API spec. for which methods you need to writeSee the API spec. for which methods you need to write

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

ListenersListeners

Need 3 things!Need 3 things!1.1. Responder implements ActionListener Responder implements ActionListener

interfaceinterface2.2. This means it implements This means it implements

actionPerformed method:actionPerformed method:public void actionPerformed(ActionEvent e) {public void actionPerformed(ActionEvent e) {

// what happens when button is pressed// what happens when button is pressed

}}

3.3. The responder must add the listener:The responder must add the listener:Say a frame has a button. Say a frame has a button. this.button.addActionListener(this);this.button.addActionListener(this);

Listens Responds (this is the frame, but could be a panel or even the button itself)

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

E.g. Button in a PanelE.g. Button in a Panel Button is the event sourceButton is the event source Panel has to respond to the event and therefore must listen for Panel has to respond to the event and therefore must listen for

events.events.

public TopPanel extends JPanel public TopPanel extends JPanel implements implements ActionListenerActionListener { { 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 this.changeColor.addActionListener(this); //Add the listener to

the sourcethe 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 }}}}

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

Do I have to write a whole Do I have to write a whole separate class in its own separate class in its own

file, just for an file, just for an actionPerformed method?actionPerformed method?

No! You could use an anonymous No! You could use an anonymous class or a function objectclass or a function object

More on those next classMore on those next class Funny that that’s the ordering of Funny that that’s the ordering of

topics…topics…

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

Finish demo togetherFinish demo together

Draw the UML for all classes so farDraw 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 Look at its Iterative Enhancement Plan togetherPlan together

CodeCode Sliders are similar, I used the Java Sliders are similar, I used the Java

Swing Tutorial for some ideas.Swing Tutorial for some ideas.

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

Start Fifteen Spec nowStart Fifteen Spec now

You need to do 2 things before you You need to do 2 things before you start coding:start coding: Show us your UMLShow us your UML Show us your Iterative Enhancement Show us your Iterative Enhancement

PlanPlan

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

UML ideasUML ideas List of componentsList of components For each componentFor 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 For which objects can I use the default Java version and which do I need to extend?version and which do I need to extend?

Frames, panels: extendFrames, panels: extend Text boxes: use Java’sText boxes: use Java’s Buttons: it dependsButtons: it depends

Do now with another team (so groups of 4) on a Do now with another team (so groups of 4) on a whiteboard.whiteboard.

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

Iterative enhancement Iterative enhancement planplan

Such a plan ensures that you always have code that Such a plan ensures that you always have code that worksworks

Each stage must be testable by running the Each stage must be testable by running the applicationapplication No looking at code!No looking at code! So “implement the Dud class” is NOT part of an iterative So “implement the Dud class” is NOT part of an iterative

enhancement planenhancement plan It is OK for some stages to include throw-away codeIt is OK for some stages to include throw-away code The stages should be about the same size/difficultyThe stages should be about the same size/difficulty

Iterative enhancement plan:Iterative enhancement plan:A A series of stages (and substages)series of stages (and substages)

by which to develop the application,by which to develop the application,with each stage with each stage testable by running the applicationtestable by running the application