aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GUI question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI question" Watch "GUI question" New topic
Author

GUI question

Alex McCormick
Ranch Hand

Joined: Mar 08, 2003
Posts: 31
Hello, I'm working on creating a cribbage game, and have a question: In building the GUI, I've been displaying the playing cards by wrapping them in a JLabel object. (Using ImageIcon) Each card's image is a GIF file that I have saved in the same folder as the .java files. This works fine, except I'm not really sure if this is the best way. For instance, as the Cribbage game is being played, the cards that are displayed are going to be constantly changing. (obviously) Every time I want to display a new card, should I be creating new JLabels? Should each of the 52 cards have it's own JLabel? This seems inefficient, so I figured there might be a more logical way to handle this.
If anyone has any ideas I would be appreciative. Thanks!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I'm moving this to the Swing / JFC / AWT forum, where those pretty user interface makin' folks might have some good advice...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Alex McCormick
Ranch Hand

Joined: Mar 08, 2003
Posts: 31
bumping to see if anyone has any ideas. thanks!
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
You could have a set of JLabels and one ImageIcon for each label. When the card that label should display changes, simply change the icon's source image using setImage() and then call invalidate() on the label and validate() on its container. You may also need to repaint(), it should work fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI question