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.
- Compile the program, then use the appletviewer to see how it works
(you may use the file Vote.html).
- Modify the program so that there are two candidates to vote for --
Joe and Sam. To do this you need to do the following:
- Add variables for Sam -- a vote counter, a button, and a label.
- 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.
- Add the button and label for Sam to the Container object.
- Compile and run the program.