I'm writing a small application in Java that will click ten different locations on my screen each minute for 10 minutes. But before doing the clicking I want to choose the locations it will click by clicking on the screen and storing the x & y coordinates in an arraylist.
I have read that I can get it by using MouseInfo however I want to get the coordinates when the mouse is clicked (which may not include being on the component). So how does one do this?
Will I have to create a see through component that takes up the entire screen and get the coordinates that way? Or is there a better way to go about this?
Try this one...
Ex: code mousemoved Event:
x=event.getX();
y=event.getY();
mouseclicked Event:
// use Event object e or event to get value of
x=event.getX();
y=event.getY();
// this is more easy than the mousemoved event..
for(...) {
if(x > rectangle[i].getMin && rectangle[i].getMax < x
&& y > rectangle[i].getMin && rectangle[i].getMax < y)
{
// your action..
}
else
{
}
}
I decided to just make a translucent window the size of the screen (which is barely visible) and collected the mouse positions that way. It seemed to work, but I was hoping that I wouldn't have to paint an extra component.
Summarized (for those that care):
So far this seems to be my best option, unless someone else mentions one shortly :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.