What are events?

• An event is an action or occurrence recognized by a computer that may be handled by software. Events are generated or triggered by the system, by the user or in other ways. 

• An event listener is a programming element that listens for a specific event such as a keypress or a mouse-click that occurs while the program is running, and responds to the event by calling an event handler.

• An event handler is an action that takes place in response to the event. The handler may be built-in Alice procedures, or a procedure created by the programmer.  


initializeEventListeners procedural method (Scene class)

• In Alice 3, all event listeners are initialized in a special procedural method of the Scene class, named appropriately, initializeEventListeners.

• Open  this procedure by clicking on the initializeEventListeners tab in the Alice 3 editor window.



• The initializeEventListener procedure already has already implemented one listener, addSceneActivationListener 

• addSceneActivationListener responds to the Run button being  clicked.

• Here, the scene activation event calls myFirstMethod as the handler, but any procedural method(s) may be called as handlers to respond to the Run button being clicked


Creating Events  

1. You may drag an event procedures from the methods panel of this or Scene object 

2. You may click the  addEventListener button located in the iniializeEventListeners tab to see the drop down menu of available listeners.


Types of Events

• Scene Activation / Time events include 

o A listener for when the run button is clicked

o A time listener that allows you to create events based on the passage of time.

• Keyboard events include listeners that

o Respond to any keypress on the jeyboard

o Respond only to arrow or number keypresses

o Allow arrow keys to move and orient a specific object in the scene

• Mouse events include listeners that

o Respond to a click on an object in the scene

o Respond to a click anywhere on the runtime window

o Allow the mouse to move an orient any object in the scene

• Position / Orientation events include listeners that

o Listen and respond to object collisions, or when objects get close to each other

o Listen and respond to objects that move into or out of the runtime window