*
The moose likes Swing / AWT / SWT and the fly likes MouseMotionListener question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MouseMotionListener question" Watch "MouseMotionListener question" New topic
Author

MouseMotionListener question

shawn larkin
Ranch Hand

Joined: Feb 04, 2002
Posts: 34
mouseDragged(MouseEvent event)
{
int valueX = event.getX();
int valueY = event.getY();
}
getting the x and the y coordinates of the mouse seem to return a relative number example(-14, 0) instead of an absolute number(546, 873). How could I get that absolute value, and not the relative value based on the component setting the MouseMotionListener. thanks
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Look up the API documentation for MouseEvent:
getX() : Returns the horizontal x position of the event relative to the source component.
The coordinates are not global to your monitor screen, they are in the coordinates within the component. -14 indicates that the mouse is now 14 pixels to the left of the left side of the component for which the mouseDragged() event was fired.


Rob
SCJP 1.4
shawn larkin
Ranch Hand

Joined: Feb 04, 2002
Posts: 34
Hi, thanks for the quick reply. I know about the not global thing, I was just wondering if you knew of a solution.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You'll have to get the Component that launched the event (via event.getSource()), get the screen location of that component(via Component.getScreenLocation()), and add the x and y location of the event to this point.

Voila! You have to x and y location of the event on the screen!

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
shawn larkin
Ranch Hand

Joined: Feb 04, 2002
Posts: 34
thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MouseMotionListener question
 
Similar Threads
Not able to find a File in servlet
absolute method in mathclass
The problem prototype Ajax.Request
question about Math class
Current value for Resultset..