我正在寫代碼,首先將鼠標位置添加到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',並在循環結束時丟棄它。那是你要的嗎? –