• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying Playing Cards...

 
Christopher Jackson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am creating a freecell application and I am having some trouble trying to figure out how to implement the tableau of cards. Currently I have a JLabel with an ImageIcon set to it to represent each type of card. My question is how should I insert the labels onto a JPanel so that the cards are tiered like in normal freecell games.

I was able to do this easily by calling paintIcon(this, page, xpos + ((xpos) * (x*xpos)), ypos) and directly painting my imageIcons on to a panel. But I had to switch to labels as I felt it would be easier to deal with labels using actionlisteners. (Correct me if my thinking is wrong, is there an easy way to handle listeners for ImageIcon painted on to a panel?)

If my thinking is right, and I should be using labels, any ideas on how to display them on the panel so they cascade? I fooled around with the diff LayoutManagers and couldnt get anything displaying the way I wanted. Any help would be appreciated.

- Chris
 
Christopher Jackson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out a way to do it. Setting the Layout to null and using setBounds on the JLabel before passing it in worked. Still curious if there is a better way to do it though. Thanks.
 
Christopher Jackson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an additional question.

I have all my JLables(cards) displayed in a single JPanel.

What would be the best way to implement keeping track of when someone drags a card on top of another card?

Would I add mouseListeners to the cards? or add listeners to the panel? I added a MouseMotionListener to the labels and can drag the cards around the screen. But I am at a loss on how I can determine what card they are dropped on top of. Any help would be greatly appreciated.

Thanks
- Chris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!