Alice Programming
Learn Alice in FREE step-by-step lessons.
Module 19: Events: Responding to the Mouse and Keyboard
Events are things that happen. In programming, some of the events that can occur are clicking or moving the mouse, typing a key on the keyboard, or other user interaction.
When these events occur, nothing will happen unless you tell the program to listen for these events and what to do when these events occur.
If we want to execute some statements when one of these events occurs, we have to tell Alice to "listen" for that event. We do this by adding a listener. We tell it what event to listen for, and what function to execute when that event occurs.
After adding an event listener, that event will trigger the execution of a procedure or function. Programmers refer to this as "Event Handling."
In this module you will learn to use event listeners to respond to the mouse and keyboard, add drag and drop and other interactive features.
Goal:
- Learn to make your program more interactive using events
- Understand that an event is something that happens
- Add a listener to code what happens when an event occurs
- Allow the user to control the action using the keyboard and the mouse
- Detect collisions and write the code for what to do when a collision occurs
- Use a timer
- Create background sounds
- Create background animation
In order to do this you will:
Objectives:
- Create code to implement event listeners for various events;
- Write code to determine which key on the keyboard was pressed;
- Write code to determine which object was clicked.
- Use control structures to specify which actions to take when an event occurs;
- Use addSceneActivationListener to create a continuous action while other actions take place;
- Play background music using initializeEventListeners;
- Write code the uses default model manipulation in event listeners to let the user drag and drop objects at run time;
- Use collision detection to make something happen when objects collide;
- Write code for the keypress event; for example typing a letter to make a selection;
- Add object mover for an object so that the user can move it with the arrow keys;
- Use the timer event to make an action occur at random intervals.