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!
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.