HW2a: Using the Button and TextField classes
Due: Wednesday, Feb 26, 2003
Write a class Player with the following properties:
- Private attributes:
name , numDice (default value 1) , maxDiceValue (a constant with a value 6)
- Constructor with the name as the argument
- Another Constructor with the name and numDice as argument
- Set and Get methods for numDice
- A method roll , which returns the sum of the value of each dice (use the Math.random method)
- Override the toString method, to return a String composing the player's name and the number of dice.
Write an applet class HW2a , which simulates
two players, the first one rolling one dice, and the other one rolling a pair of dice.
Use Text fields to display the values for each player.
Also, use a text field to display the result. All the text fields are not
You can use boolean variables to keep track of the current player.
To change the label on the JButton object, use the setText(...) method.
- In the paint method, indicate the play round. Make sure you call super.paint(g) as the first call.
- Include a link to the source code of your applet.