I'm writing an application that displays "playing cards". I have gif files for all the cards, such as "aceclubs.gif", "sevendiamonds.gif", etc. I'm displaying the cards using JLabel like this ... JLabel fred = new JLabel("hello", cardImageIcon, JLabel.CENTER); (where cardImageIcon is an image icon). Now, when I press a button, I want to change the card displayed to a different card. Can't seem to do it. It seems that Java lets me change the text (i.e. "hello" to "goodbye") but won't let me change my image from "aceofhearts.gif" to "twospades.gif") If not ImageIcon ... what should I use? Should I use something other than JLabel? Thanks!
If you are needing to change cards, there is a better way than changing the image. Create all your cards in one sweep adding the images needed to each card. You can use whatever component you wish to hold the JLabel. Personally I would use a JPanel or even a JButton (easier to catch click events) and place a JLabel with an ImageIcon on one of those. Use the CardLayout to place your cards. That way you can stack them. Card Layout uses an int to keep track of where the card is in the stack. If you need to display a new card, just move that card to the top of the Layout. Does that make sense?