Hi all, I'm working on a Cribbage game (and have been for a while now!). I've got the majority of the game logic done, but what's really frustrating me is the GUI. I'm using Swing (probably not very well), and I'm not sure what the best way is for the user to click on cards - such as for discarding, playing a card during the "pegging" phase, etc. Currently, I've got a very crude GUI that displays the players cards with a JRadioButton underneath each card. The user clicks the radiobuttons of the cards he/she wants to discard, then clicks a "discard" button. This works, but it looks a little amateurish. I've seen other card games where if you click the card, it actually moves. (some type of animation, I guess?) I'd even settle for the ability to just click the card and have the card "highlighted" in some fashion before clicking the discard button, rather than using radio buttons for the selection process. Is there a class or classes in the Java library that I should take a peek at for this type of thing, or is there no easy way to do this?
The icon can be placed on the constructor of JLabel so you don't have to worry about the image loading etc. The JLabel is then placed on the gameboard that has some kind of layout (or you can do it yourself with custom painting).
Thanks for the help guys, I think I might try a combination of both ideas to see which I like best. Currently, I'm displaying the cards as an ImageIcon within a JLabel. From what Saara said, I think I could use the MouseListener interface to capture when a user clicks on the JLabel, which could then run something like: cardLabel1.setEnabled(false);
which would "grey out" the card - making it appear as though the user selected it to be discarded. If I can't get that to work well, though, then I may try the JButton approach and just put the ImageIcon inside the button. I may have more questions after I try implementing these approaches, so you may hear back from me! Thanks again!