Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2003

Tip: Looking for answers? Try searching our database.

Displaying overlapping card hand

Thread view: 
Paul Carey - 11 Dec 2003 10:24 GMT
Hi

I'd like to display a hand of playing cards in a fan shape with the
cards overlapping one another. The cards will need to be able to
respond to mouse clicks. If the mouse is over two cards, only the card
that's visible should receive MouseEvents. I was wondering if anyone
could suggest how I might approach this.

A couple of possibilities occured to me, but I'm not sure how
reasonable/unreasonable they are:
- Represent the Cards by subclassing Image, adding a z-index variable
and have my subclass implement MouseAdapter. Display the cards on a
JComponent, performing AffineTransformations as necessary on the
Cards. I'm not sure how easy it will be to detect when the mouse is
over a card that's been rotated though.

- Create a JLabel with an ImageIcon for a card, add the JLabel to a
JPanel. This works as a represntation for a card, but I don't know if
it's possible to skew or rotate a JPanel?

Any ideas would be very welcome
Thanks

Paul
Roedy Green - 11 Dec 2003 22:09 GMT
>- Represent the Cards by subclassing Image, adding a z-index variable
>and have my subclass implement MouseAdapter. Display the cards on a
>JComponent, performing AffineTransformations as necessary on the
>Cards. I'm not sure how easy it will be to detect when the mouse is
>over a card that's been rotated though.

To figure out which card has been hit, it will be up to you to process
the mouse click event. I would pre-compute the co-ordinates the
rotated bounding rectangle for each card, and check the cards in
order, top most first to see if the click point was inside.

I vaguely recall a deprecated "inside" method in some class for
helping you do this.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Paul Carey - 12 Dec 2003 11:51 GMT
> >- Represent the Cards by subclassing Image, adding a z-index variable
> >and have my subclass implement MouseAdapter. Display the cards on a
> >JComponent, performing AffineTransformations as necessary on the
> >Cards. I'm not sure how easy it will be to detect when the mouse is
> >over a card that's been rotated though.

> I vaguely recall a deprecated "inside" method in some class for
> helping you do this.

Thanks Roedy. I looked it up in the index, it's been replaced by
contains(...) which is implemented by Polygon.
Jan Schaefer - 12 Dec 2003 11:27 GMT
Paul Carey schrieb:
> I'd like to display a hand of playing cards in a fan shape with the
> cards overlapping one another. The cards will need to be able to
> respond to mouse clicks. If the mouse is over two cards, only the card
> that's visible should receive MouseEvents. I was wondering if anyone
> could suggest how I might approach this.

I did it this way in my card game:

- make a panel holding all cards (FlowLayout)
- set setHgap to 0
- make a panel for each card and
  overwrite paintComponent-method of each panel
  to add the image for this card
- set preferredSize for each panel
  if card should be overlapped make preferredSize smaler
  if card is fully visible make preferredSize == image size
- add all card panels to the holding panel

Now you have every card in it's own panel that can catch mouse clicks.

I can post some source code if you want...

So long,

Jan


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.