CSC 216 F09/ActionListener

From Expertiza_Wiki
Jump to navigation Jump to search

ActionListener Charades

[1]

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

  1. Two students will be chosen for this part of the exercise.
  2. One student will be the ActionListener and the other the actor.
  3. The ActionListener will be given the 4 envelopes containing each action.
  4. The instructor will click on a button and the ActionListener will read the correct action to the actor based on which button was pressed.
  5. If the ActionListener reads the correct action and the actor performs the correct action, play will return to the previous step.
  6. If either the ActionListener or the actor fail, play ends and new contestants are chosen.
  7. If play continues until all actions are performed, the ActionListener and the actor "win" the game.

Part 2: Separate ActionListeners

  1. Five students will be chosen for this part of the exercise.
  2. Four students will be ActionListeners assigned to specific buttons and the fifth will be the actor.
  3. Each ActionListener will get the envelope holding the action specific to his/her button.
  4. The instructor will click on a button and the corresponding ActionListener will read the action to the actor.
  5. If the correct ActionListener reads the action and the actor performs the correct action, play will return to the previous step.
  6. If either the ActionListener or the actor fail, play ends and new contestants are chosen.
  7. 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