CSC 216 F09/ActionListener
ActionListener Charades
Background
Two Implementations of ActionListeners
The first way is to create a single ActionListener which has a logical test (such as an IF statement) that determines which action was performed and then calls the function required when that action is performed. The second way is to have separate ActionListeners which will be invoked whenever their specific action is performed.
Props
The props required for this exercise will be a projector showing four buttons and envelopes with a number written on them and a paper describing a function to be performed inside.
Procedure
Part 1: Single ActionListener
- Two students will be chosen for this part of the exercise.
- One student will be the ActionListener and the other the actor.
- The ActionListener will be given the 4 envelopes containing each action.
- The instructor will click on a button and the ActionListener will read the correct action to the actor based on which button was pressed.
- If the ActionListener reads the correct action and the actor performs the correct action, play will return to the previous step.
- If either the ActionListener or the actor fail, play ends and new contestants are chosen.
- If play continues until all actions are performed, the ActionListener and the actor "win" the game.
Part 2: Separate ActionListeners
- Five students will be chosen for this part of the exercise.
- Four students will be ActionListeners assigned to specific buttons and the fifth will be the actor.
- Each ActionListener will get the envelope holding the action specific to his/her button.
- The instructor will click on a button and the corresponding ActionListener will read the action to the actor.
- If the correct ActionListener reads the action and the actor performs the correct action, play will return to the previous step.
- If either the ActionListener or the actor fail, play ends and new contestants are chosen.
- If play continues until all actions are performed, the ActionListener and the actor "win" the game.
Attribution
This exercise created by Benjamin Fitzgerald and Andrew Warren-Love