aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes To get the coordinates of mouse pointer... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "To get the coordinates of mouse pointer..." Watch "To get the coordinates of mouse pointer..." New topic
Author

To get the coordinates of mouse pointer...

sumukha kris
Greenhorn

Joined: Nov 02, 2007
Posts: 18
Hello,

how can i get the coordintes value of the mouse pointer within the frame . I need this to draw a rectangle , when the user clicks on one of the position and drags it a rectangle has to be drawn . The starting point of the rectangle should be pixel positions of the mouse pointer when the user clicks and ending point should be pixel co ordinates when the user releases the mouse button. Can anybody help me with this.

Thanks in anticipation,
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

You need to add mouseListener and mouseMotionListener to the frame. The mouse event has getX() and getY() methods which will give you the co-ordinates you want.
You might also want to read this tutorial.

Also, the MouseInputAdapter will be helpful to you so that you need to implement only the methods you really require.

Best of luck.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To get the coordinates of mouse pointer...