Home arrow static arrow Java Programming [Archive] - Get co�rdinates of a clicked point
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Get co�rdinates of a clicked point
This topic has 2 replies on 1 page.

Posts:4
Registered: 3/23/04
Get co�rdinates of a clicked point  
Jun 17, 2004 11:35 AM



 
hello,

I have a board for a boardgame. I wanted to define the areas in if-statements so that I could regard witch field it was. But if I click on field 1,1 (between x = 30 and x = 100 and between y=30 and y=100 for example) and there is a piece (a canvas) on it, I cant get the co�rdinates of the mouseClicked event.

What can I do about this?

Daan
(holland)
 

Posts:484
Registered: 9/20/02
Re: Get co�rdinates of a clicked point  
Jun 17, 2004 11:43 AM (reply 1 of 2)



 
You can use [url=http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/SwingUtilities.html#convertPoint(java.awt.Component, int, int, java.awt.Component)]SwingUtilities.convertPoint[/url] to convert between coordinate systems. Is this what you're asking?
 

Posts:1,381
Registered: 00-02-19
Re: Get co�rdinates of a clicked point  
Jun 17, 2004 1:24 PM (reply 2 of 2)



 
Not sure what your problem is. However, getting a mouse click is simple and easy, and when you catch the event, you can say getX() and getY(). It doesn't matter what graphics are being displayed. The mouse event is an operating system call that gets sent to the Java VM. It has no idea if a piece is there or not. It should work regardless.
 
This topic has 2 replies on 1 page.