DOC PREVIEW
Duke CPS 004 - Chapter 4

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4Chap 5 Sec 2 Oct 18, 2005Prof. Susan RodgerNote: thanks to Wanda Dann and Steve Cooper for slide ideasAnnouncements• Read Chapter 6 Tips and tech for next time• Assignment 5 – Part 1, due today– Part 2, due next weekWhat we will do today• Lecture on Chap 5, Sec 2 – Event-handlers with parameters• ClassworkMouse Clicks• Interactive programs – allow user to mouse click an object– Buttons in an interface– Targets in a game– Checklist of items on a form• Will see how to pass information about a mouse clicked object to an event handlerExample• People are trapped in a burning building• Select which person will be rescued Storyboard• Three people are to be rescued• Could write 3 different methodsEvent: click on guy1Responding Method:Save guy on first floorEvent: click on girl3Responding Method:Save girl on third floorEvent: click on girl2Responding Method:Save girl on second floorA Better Solution• Write one event handler• Send in information needed for actionfiretruck.savePerson:parameters: whichFloor, whichPerson, howFarDo in orderpoint ladder at whichFloorextend ladder howFar meterswhichPerson slides down ladder to fire truckpull ladder back howFar metersWhat type are the parameters?Demo• Demonstration of the code forfiretruck.savePersonThree Events• The argument sent to parameters depends on which person is mouse clicked• Note - we positioned fire truck so distance from floor X is X meters (to floor 3 is 3 meters)Example 2 – put events in• Zeus was a powerful god in Greek mythology. When Zeus was angry, he would shoot a thunderbolt out of the heavens to strike anyone who got in the way• The user will choose the philosopher who will be the next target of Zeus’ anger.Storyboard• Possible design – method with Object parameter named who, for object clicked– The actions in storyboard are complex– Break actions into simpler steps using stepwise refinementEvent: an object is mouse-clickedEvent handler: shootBoltParameter: who – object clickedDo in orderprepare to strike object that was clickedthunder plays and lightning strikes object clickedlightning is repositioned for next strikeEvent: an object is mouse-clickedEvent handler: shootBoltParameter: who – object clickedDo in orderprepare to strike object that was clickedthunder plays and lightning strikes object clickedlightning is repositioned for next strikeprepareToShootParameter: targetDo togetherturn Zeus to face the targetmake the lightning bolt visiblelightning and Thunder:Parameter: targetDo togetherplay soundcall specialEffects method- send targetspecialEffects:parameter: targetDo in orderDo togetherlightning bolt move to targetsmoke move to targetDo togetherset smoke to visibleset lightning to invisiblecall smoke cycle – built-in methodset target color to blackmove target up and downA Driver• shootBolt method - top level of our design• It calls other methods and controls the overall action of the program – we call this a driverOne Link• In the fire rescue example, we used three links – one for each person in the burning building.• In this example, we use only one link by selecting “object under mouse cursor” as the argument.prepareToShoot• In setting up initial scene, made lightning bolt invisible by setting its opacity to 0 (0%)• To prepare to shoot lightning bolt, make it visible, set opacity back to 1 (100%)lightningAndThunder• Coordinate the sound of the thunder with lightning and other special effectsspecialEffects• Smoke.cycle is a built-in instruction with a duration of about 2 ½ secondsDemo• Test run of Zeus world – (this version doesn’t have the if statements from Chap 6 added in)• When parameters are used in interactive programming –especially important to test that all possible parameter values work as expected– What happens if you click on each philosopher, one at a time?• Also try things that shouldn’t work– What happens if you click on a column?– What happens if you click on a philosopher twice?– What happens if you click on Zeus?Classwork today• Create 2 worlds (or can combine them)– Problem 14, page 140– Problem 15, page 141 (can use any


View Full Document

Duke CPS 004 - Chapter 4

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Chapter 4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?