Event Driven Programming Chapter 5. Sequential Programming Computer-Centric Computer-Centric Program Runs as Programmer Intended Program Runs as Programmer.

Slides:



Advertisements
Similar presentations
PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU.
Advertisements

Alice Inheritance and Event Handling. Inheritance Concept Consider this hierarchy; parents describe properties of children Animals Vertebrates MammalsFish.
Events Chapter 7. Interactivity The real world is interactive User determines order of actions instead of programmer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Parameters and Event-Handler Methods Alice. Mouse input Interactive programs often allow the user to use a mouse to click buttons in a windows-based interface.
Parameters and Event-Handler Methods Sec 50 Web Design.
Introduction to Alice Web Design Section 8-2 Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Interaction: Events and Event Handling
Alice 2.0 Introduction to Event-Driven Programming Mr. Planck.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University Feb. 24, 2007.
Introduction to Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Sequencing Miss Regan. Blood Hound  Does anyone know what the Bloodhound project is?  Video 1 Video 1  Video 2 Video 2  Link to website Link to website.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Execution Control with If/Else and Boolean Functions
CSC1401: Introductory Programming Steve Cooper
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Alice: Functions Alice Chapter 6 September 19, 2005.
Interaction: Events and Event Handling
Parameters and Event-Handler Methods Sec 50 Web Design.
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
Summer Computing Workshop. Session 2 Input in Scratch  Multi-Character input - This is used when the user is prompted to enter a number or word.  Problems.
Events (2) (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Today’s Agenda 1.Collect Pre-Lab 5 2.Collect Alice project storyboards 3.Events 4.Dummy Objects 5.Assign pair programming teams and meet upstairs for Lab.
Parameters and Event-Handler Methods Alice. Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in.
Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
CS320n – Elements of Visual Programming Sending Parameters to Event Handler Methods (Slides 5-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Introduction to Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Introduction to Alice Web Design Section 8-2 Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Chapter 5 Interaction: Events and Event Handling.
CompSci 4 Chap 5 Sec 2 Oct 9, 2008 Prof. Susan Rodger.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
Interactive Programming MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project.
1- How to connect the robot to the pc Sec Getting Started 3- How to move the robot Sec Scribbler movements 4- How to make a turn 11- How to.
Fall 2008ACS-1805 Ron McFadyen1 Event-driven programming Chapter 5 covers event-driven programming. Events are user or condition driven and so each event.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Task 2f – part a Prove that you can receive an WITH an attachment, open it AND save the attachment to your user area. Open the with the attachment.
Starting Out with Alice: A Visual Introduction to Programming
Event-driven programming
Obj: Introduction to Alice
Introduction to Alice Alice is named in honor of
Introduction to Events
Introduction to Alice Alice is named in honor of
Parameters and Event-Handler Methods
Interactive Programming
Introduction to Alice Alice is named in honor of
Parameters and Event-Handler Methods
Parameters and Event-Handler Methods
Introduction to Alice Alice is named in honor of
ICT Programming Lesson 5:
Chapter 13: Handling Events
ACM programming contest
Event-driven programming
Parameters and Event-Handler Methods
Interactive Programming
Presentation transcript:

Event Driven Programming Chapter 5

Sequential Programming Computer-Centric Computer-Centric Program Runs as Programmer Intended Program Runs as Programmer Intended Programmer Sets the Order of Action Programmer Sets the Order of Action Programmer Controls the Program’s Flow Programmer Controls the Program’s Flow

Event Driven Programming User-Centric User-Centric Computer User Determines the Order of Actions Computer User Determines the Order of Actions Programs are Interactive Programs are Interactive Flow of Control is Determined at Runtime Flow of Control is Determined at Runtime User Clicks Mouse / Presses KeyUser Clicks Mouse / Presses Key Object in Scene Moves to create a ConditionObject in Scene Moves to create a Condition

Event Something that happens Something that happens Can be caused by computer or user Can be caused by computer or user Mouse ClickMouse Click Key PressKey Press System Clock TickSystem Clock Tick Can occur differently each time the program is executed Can occur differently each time the program is executed Events are WORLD Level Events are WORLD Level

Event Handling Response to an event Response to an event Action or Sequence of Actions carried out when Event Occurs (Methods) Action or Sequence of Actions carried out when Event Occurs (Methods) Events TRIGGER response Events TRIGGER response Programmer must think of all possible events Programmer must think of all possible events Plan a Response for Each (Event Handler)Plan a Response for Each (Event Handler)

Linking Event Handling Methods must be linked to the Specific Event Event Handling Methods must be linked to the Specific Event Event Occurs which causes the Event Handling Method to execute

Testing Testing of Event Driven Programs is much more difficult Testing of Event Driven Programs is much more difficult Programmer does not know flow of programProgrammer does not know flow of program Flow of Program changes every time program is executedFlow of Program changes every time program is executed User’s Actions are difficult to pre-determineUser’s Actions are difficult to pre-determine Use Incremental Development and Testing Use Incremental Development and Testing Write a MethodWrite a Method Test itTest it Write a MethodWrite a Method Test itTest it Etc.Etc.

Example Program Create a “Whack A Mole” program. Use the whackAmoleBooth object from the amusement park gallery. Create a “Whack A Mole” program. Use the whackAmoleBooth object from the amusement park gallery. Pressing the “M” key makes the mole pop upPressing the “M” key makes the mole pop up Clicking the mouse on the mole makes the bopper try to hit the moleClicking the mouse on the mole makes the bopper try to hit the mole

Design Storyboards Event: Key Press Letter M Response: Make mole lift out of booth Mole says “Get me if you can!” Make mole go back into booth

Design Storyboard Event: Mouse Click on Mole Object Response: Lift Bopper off Booth Move Bopper to Booth towards Mole Lift Bopper off Booth

Create Methods World Level or Class Level Methods? World Level or Class Level Methods? WhyWhy Create moleAppear method Create moleAppear method

Linking Event to Method Create New Event Create New Event When a Key is Typed When a Key is Typed

Linking Events to Methods Select Specific Key Select Specific Key M  Make Mole Appear M  Make Mole Appear

Link Event to Method Select Method to Link Select Method to Link wackAmoleBooth, moleAppears wackAmoleBooth, moleAppears TEST TEST

Create Method Create bopMole method Create bopMole method Link to Mouse Click on Mole Event Link to Mouse Click on Mole Event Test Test

Run the Program Try to Whack The Mole Try to Whack The Mole Click “M” to make moleAppear Event Handling Method executeClick “M” to make moleAppear Event Handling Method execute Mouse Click on Mole to make bopMole Event Handling Method executeMouse Click on Mole to make bopMole Event Handling Method execute

Homework Chapter 5 Chapter Exercises 5-1 Exercises 1  Flight Simulator1  Flight Simulator 4  Typing Tutor4  Typing Tutor

Events with Parameters Remember: Parameters are how we send information to the methods Remember: Parameters are how we send information to the methods Customize Methods for different objects/valuesCustomize Methods for different objects/values

Create Scenes/Methods Example: (Textbook page 125) Example: (Textbook page 125) A firetruck has been called to an emergency in a burning building. A person and a fire object has been placed on each floor. When each person is selected, the truck will need to extend its ladder so that each person can climb down to safety.

Design Event 1 – Click on 1 st person Event 1 – Click on 1 st person Responding Method – Save person on 1 st floor Responding Method – Save person on 1 st floor Event 2 – Click on 2 nd person Event 2 – Click on 2 nd person Responding Method – Save person on 2 nd floor Responding Method – Save person on 2 nd floor Event 3 – Click on 3 rd person Event 3 – Click on 3 rd person Responding Method – Save person on 3 rd floor Responding Method – Save person on 3 rd floor

Design 2 Events: Click on Person Events: Click on Person Responding Method: SavePerson Responding Method: SavePerson Point the ladder at the correct floor (parameter – Which floor) Extend the ladder correct amount (parameter – How far) Specific person (parameter – Which person) slides down ladder to the firetruck Pull the ladder back in correct amount (parameter – How far)

Create Scene Burning Building (building) Burning Building (building) Firetruck (vehicles) Firetruck (vehicles) 3 People – use whichever you want 3 People – use whichever you want RandomGirl1RandomGirl1 RandomGirl2RandomGirl2 RandomGuy2RandomGuy2 FireAnim – FireAnim – GalleryGallery Save As name.a2c (not ZIP file)Save As name.a2c (not ZIP file) Put in correct Alice gallery folder: Put in correct Alice gallery folder:Alice\Alice\Required\Gallery\

Create Method as Before World Method or Class Method? World Method or Class Method? Parameters: Parameters: whichFloor (object)whichFloor (object) whichPerson (object)whichPerson (object) howFar (number)howFar (number)

SavePerson Method

Link Method to Event

Test the Program Run the program Run the program VERY Important when using parameters VERY Important when using parameters Run several timesRun several times Number ParametersNumber Parameters Small Number Small Number Large Number Large Number Negative Number Negative Number

Complex Problems Responses to events may involve multiple actions Responses to events may involve multiple actions Methods can call other methods Methods can call other methods Parameters can be used when methods call methodsParameters can be used when methods call methods

Homework Problems 12 & 14Problems 12 & 14