Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI question

 
Alex McCormick
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the Swing / JFC / AWT forum, where those pretty user interface makin' folks might have some good advice...
 
Alex McCormick
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bumping to see if anyone has any ideas. thanks!
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic