views:

140

answers:

1

In my code, I use mouse coordinates to interact with the program. From there, something must be drawn at the mouse's location. However, the getX()/getY() methods for the Canvas return the values of the window holding the Canvas, but when I go to draw, (0,0) is located slightly to the right and below (past the bars) the top left of the window, resulting in being approximately 30 pixels off of the correct location. Is there a way to reconcile the differences, or should I simply fullscreen the window or use some other method to sidestep the problem altogether?

+4  A: 

I guess you registered the MouseListener and MouseMotionListener to the window. Register them for the Canvas and you get coordinates relative to this widget. See this sample code.

Aaron Digulla