I have got a Dice program that displays dice on a JPanel in the form of a button.
To instantiate the Jbuttons/dice I use:
Dice die1 = new Dice(diceModel.getFaceNumber());
This applies a corresponding face image with the number that is retrieved.
If I click the button the rollDice method is called which retrieves another random number and gets a new face image. The problem I have is that I don't know how to apply this face image to die1 and how to repaint it on the panel.
I have tried using Dice die1 = new(etc, etc, but I just get a totally different dice. All I want is to refresh the current die1 button with a new image. Any ideas?
The roll Dice method uses setIcon(icon) and I'm pretty sure that the correct image is being generated its just that I can't seem to display it.
Please post the Dice class so we can see where the problem is. Does Dice extend JButton? If so, you should be able to setIcon() on it again when rolling without having to repaint it yourself.