This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Dice Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Dice Program" Watch "Dice Program" New topic

Dice Program

Chris G Johnson

Joined: Nov 20, 2004
Posts: 23
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.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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.
Chris G Johnson

Joined: Nov 20, 2004
Posts: 23
Yeah it does extend JButton , but I can't post the code at the minute as i'm at work. I will post it about 5.00pm. Cheers
Chris G Johnson

Joined: Nov 20, 2004
Posts: 23
This is the Dice class:-

This is my diceView class:-

Andy Rayner
Ranch Hand

Joined: Dec 09, 2004
Posts: 36
do you happen to be at leeds met university doing software development techniques? *grins*
subject: Dice Program
Similar Threads
Need Help Understand this.
Dice Program Desparate Help!!!
Just a little question
Variables assigned to objects
no main method found