我正在写代码,首先将鼠标位置添加到arraylist(with dealys),之后,它将由moveMouse(robot)重复。我认为我做得很好。但它不起作用。谁能帮我?谢谢!Java机器人不工作
代码: CoursorMove
public class CoursorMove {
private ArrayList<Point> coordinates = new ArrayList<>();
public void addNewObjectWithCoordinates() {
coordinates.add(MouseInfo.getPointerInfo().getLocation());
}
public Point getCoordinate(int index) {
return coordinates.get(index);
}
public void play() {
for (int i = 0; i < 5; i++) {
CoursorMove bang = new CoursorMove();
bang.addNewObjectWithCoordinates();
System.out.println(bang.getCoordinate(0).getX());
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
int howmany = coordinates.size();
int index = 0;
public int getHowmany() {
return howmany;
}
public void setHowmany(int howmany) {
this.howmany = howmany;
}
public void moveCoursor() {
while (index < howmany) {
try {
Robot robot = new Robot();
robot.mouseMove(coordinates.get(index).x, coordinates.get(index).y);
robot.delay(1500);
} catch (AWTException e) {
System.err.println("Error CM 68L"); // error CoursorMove class
// Line 68
e.printStackTrace();
}
index++;
}
}
}
主。
public class Main {
public static void main(String[] args) {
CoursorMove triup = new CoursorMove();
triup.play();
triup.moveCoursor();
}
}
请描述发生VS应该用[MCVE]发生什么。谢谢 –
提示:'CoursorMove bang = new CoursorMove();'在每个for循环中创建一个全新的'bang',并在循环结束时丢弃它。那是你要的吗? –