samedi 21 mai 2016

Java robot doesn't working

I was writing code who first adding mouse posiition to arraylist (with dealys) and after will repeat by moveMouse (robot). I think that i'm doing all well. But its not working. Anyone can help me? Thanks!

Code: 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++;
    }
}
 }

Main. public class Main {

public static void main(String[] args) {
    CoursorMove triup = new CoursorMove();
    triup.play();
    triup.moveCoursor();
}

}

Aucun commentaire:

Enregistrer un commentaire