Vote Counter

The file VoteCounter.java contains a slightly modified version of PushCounter.java in Listing 5.13 of the text. As in the text the program counts the number of times the button is pushed; however, it assumes ("pretends") each push is a vote for Joe so the button and variables have been renamed appropriately.

  1. Compile the program, then use the appletviewer to see how it works (you may use the file Vote.html).

  2. Modify the program so that there are two candidates to vote for -- Joe and Sam. To do this you need to do the following:
    1. Add variables for Sam -- a vote counter, a button, and a label.
    2. Add a new inner class named SamButtonListener to listen for clicks on the button for Sam. Instantiate an instance of the class when adding the ActionListener to the button for Sam.
    3. Add the button and label for Sam to the Container object.

  3. Compile and run the program.