CSC 216 F09/ActionEvents

From Expertiza_Wiki
Revision as of 16:22, 16 November 2009 by Sdelliot (talk | contribs)
Jump to navigation Jump to search

Listen to this!

By, Steven Elliott, Eric Lumpkin, Ryan Orning

Purpose:

This game is intended to give beginning and intermediate java classes an opportunity to understand the concept behind action events in relation to GUI programming. This game is intended to be informative, interactive, and at the same time entertaining.

Supplies:

  • 6 willing participants
  • 3 pieces of paper with the button names on them. Try to make them ambiguous so that the action performed does not know what the action will be.
    • JButton button1 = new JButton;
    • JButton button2 = new JButton;
    • JButton button3 = new JButton;
  • 3 pieces of paper that are folded in half. Write the if/else statements that correspond to the button names, on the outside of the paper. The inside should have some fun but not demeaning task. Use Pseudo-code to keep the example realistic.
    • /*outside of paper*/ if(e.getSource() == button1) /*inside of paper*/ {/* insert action here */}
    • else if(e.getSource() == button2) {/* insert action here */}
    • else if(e.getSource() == button3) {/* insert action here */}

Set up:

Have 3 of the volunteers be the buttons. Give each button a piece of paper with the button name on it. The buttons should NOT look at the paper. Then have your other 3 volunteers be the actionPerformed method. They should stand in order. With the else’s being after the first if statement. They CANNOT look at their action. This will be more entertaining for the class and also shows that the actionPerformed method is unaware of the task until it is activated.

Playing the Game:

Have the class “push” (pick) a button. The button then takes the paper with the name on it and hands it to the first if statement. The if/else’s should run as a normal program would and pass the paper to the next one until the action is carried out. Once the paper gets to the correct if statement, the action within the statement should be carried out. Then repeat until all the buttons/actions have been preformed.

Example actions:

  • Jumping jacks
  • Saying a phrase System.out.speak(“Java is my favorite language”);
  • Writing a phrase on the whiteboard.
  • Etc.