Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dice Program

 
Chris G Johnson
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the Dice class:-



This is my diceView class:-

 
Andy Rayner
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you happen to be at leeds met university doing software development techniques? *grins*
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic