• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Dice Program

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the Dice class:-



This is my diceView class:-

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you happen to be at leeds met university doing software development techniques? *grins*
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic