SLIDE 2 2
Alice in Action with Java 3
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 Java 4
More on Events
– Mouse event: triggered by mouse movement or click – Keyboard event: triggered when user presses a key – Program event: triggered when variable value changes
- Conflicts can arise when coding parallel event logic
– Example: two handlers modify the same property
– Ensure that handlers modify a property in sequence