Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture 09 25 September 2012.

Slides:



Advertisements
Similar presentations
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
Advertisements

Microsoft® Small Basic
PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU.
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.
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
Flash Workshop Flash Workshop :: Agenda  Introductions  Look at a few Flash Examples  Flash Web Sites  Flash Web Applications  Flash Games.
Alice in Action with Java
Exploring Events. Try this Start Alice and create a blank world using the grass template. Add an instance of a BlueBallerina. Add an instance of a PinkBallerina.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
Scripts  Director’s scripting language is called Lingo  Lingo can be used to offer your users navigational control of the order of the scenes of your.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Visual Basic Chapter 1 Mr. Wangler.
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.
MVC pattern and implementation in java
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Welcome to CIS 083 ! Events CIS 068.
Chapter 8: Writing Graphical User Interfaces
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Sketchify Tutorial Defining Interaction and Logic in Sketchify sketchify.sf.net Željko Obrenović
Interaction: Events and Event Handling
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
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.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Flow Control: Repetition with For Loops (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Flow Control: boolean expressions, “if” selection statements (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Programming in the Simple Raster Graphics Package (SRGP) Chapter 2.
Alice in Action with Java Chapter 5 Lists and Arrays.
Variables (Alice In Action, Ch 3) Slides Credit: Joel Adams, Alice in Action CS120 Lecture 04 7 September 2012.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Methods (part 2) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS 120 Lecture 03 4 September 2012.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Creating User Interfaces Event-Driven Programming.
Tutorial 7 Creating Animations. XP Objectives Learn about animation Create a timeline Add AP divs and graphics to a timeline Move and resize animation.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Flow Control: Repetition with While Loops (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
1 Chapter 3 Event-Driven Programming. 2 Objectives F To explain the concept of event-driven programming (§12.2). F To understand event, event source,
Methods (part 1) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS120 Lecture August 2012.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
Functions (Alice In Action, Ch 3) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Starting Out with Alice: A Visual Introduction to Programming
Event-driven programming
Chapter 8: Writing Graphical User Interfaces
Introduction to Programming the WWW I
Lesson 1: Buttons and Events – 12/18
Introduction to Events
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Interactive Programming
Interactive Programming
Presentation transcript:

Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012

Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use events to build interactive stories

Alice in Action with Java3 Events Event: action generated by a user or a program –Ex: clicking the Play button will generate “ When the world starts ” event Interactive programs, such as games, are event-driven Two steps to making a program respond to an event –Choose or define a method to handle the event Such a method is called an event handler Define an event handler when responsive behavior is complex –Tell Alice to invoke the method when the event occurs

Alice in Action with Java4 More on Events Conflicts can arise when coding parallel event logic –Example: two handlers modify the same property How to avoid conflict –Ensure that handlers modify a property in sequence Event categories –Mouse event: triggered by mouse movement or click –Keyboard event: triggered when user presses a key –Program event: triggered when variable value changes

Alice in Action with Java5 Events (continued)

Alice in Action with Java6 Handling Mouse Clicks: The Magical Doors Castle door tells random knock-knock jokes Events that will be added to the original program –Right door opens when the user clicks it –Left door tells knock-knock joke when the user clicks it

Alice in Action with Java7 The Right Door First step: stop door from automatically telling jokes by making world.my first Method do nothing Recall the two steps to handle an event –Use a predefined method or define a new method –Create an event that invokes the handler Enabling the right door to respond to a mouse event –The door open/close motion feels simple  let us choose turn() to handle the event –Add When the mouse is clicked on something –Specify castle1.door as the event source

Alice in Action with Java8 The Right Door (continued)

Alice in Action with Java9 The Left Door Enabling the left door to respond to a mouse event –Specify castle.door2 as the source of this event –Drag-and-drop world ’s random joke method as handler Test the program by clicking each door

Alice in Action with Java10 The Right Door Revisited Logic error: right door continues to turn with user click Right door should open if closed, and close if open –i.e. exhibiting the two-state behavior General approach for dealing with multi-state behavior –Add an object property variable to store the object state –In object methods, use control flows such as the if statement to generate appropriate actions and perhaps also change the object state value afterwards

Alice in Action with Java11 The Right Door Revisited Fix: implement two-state behavior for right door –Add Boolean property rightDoorClosed to castle –Replacement handler: openOrCloseRightDoor() –Build turn logic around the value of rightDoorClosed

Alice in Action with Java12 The Right Door Revisited (continued)

Alice in Action with Java13 Event Handling is Simultaneous Example: left door tells jokes while right door turns Alice handles simultaneous events well

Alice in Action with Java14 More on Events Conflicts can arise when coding parallel event logic –Example: two handlers modify the same property How to avoid conflict –Ensure that handlers modify a property in sequence Event categories –Mouse event: triggered by mouse movement or click –Keyboard event: triggered when user presses a key –Program event: triggered when variable value changes

Alice in Action with Java15 Summary Event: action generated by a user or a program User events: keyboard events and mouse events Event handler: method called in response to an event Event-driven program: program directed by events and handlers Two-state behavior: pattern that switches the state of an object

Student To Do’s Readings: –Alice in Action, Chapter 6 Homework posted on Web –Demo next Monday in Lab 16