• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

GUI question

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bumping to see if anyone has any ideas. thanks!
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He baked a muffin that stole my car! And this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic