Java Genesis

Hints for Chapter 10: Graphical Components

Problem 8: a GUI to toss a die

Consider first the class DieTossPanel. This class will be responsible for painting the simulated die on the panel. This will involve painting a square and inside that square painting an integer between 1 and 6, although when the panel is first created there should be no number in the square. The colour of the square toggles between red and blue for every toss of the die. There will also need to be a method to simulate the tossing of the die.

There are many ways this can be done. Try it before looking at the next hint.


Next Hint