This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
If you have a component, then this component can catch every mouse event, for example mouse moved event. This event keeps the information of the current position. You can hold this information in a member (Point) and if the time comes, where you need the information, you will have it. This is the way I would go.
if e is MouseEvent then int x = e.getX(); int y = e.getY(); would be the point where the mouse was clicked. Jawad
Joined: Oct 22, 2002
I guess I wasn't clear. If the mouse is not clicked, and not over my component and the user presses some key (F6 for instance), at that point I want to use the Robot class to do some things with the mouse, move it, click some things, etc...and then return it to it's original location. So what I need is a way to get the original (current) location of the mouse without having to depend on the MouseEvent. Ideas?
If the mouse is not in a component listening for mouse events (i.e. if it's hanging out on the windows desktop outside of your application) then there's nothing you can do to get the mouse location. Searching for resources on this led me to find there used to be a class called EventQueueMonitor in some really early com.sun package for Java Accessability that did this, but there is no way currently provided to do this...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.