I have a specific method that saves my mouse x and y coordinates. I want that mouse coordinates be saved by specific time (for example after 1000ms). How I need to do that in Java? Please add a simple usage example.
public void mouseMoved(MouseEvent e) {
currentX = e.getX();
currentY = e.getY();
if(enemy.onWall() == true){
timer.schedule(new TimerTask(){
public void run() {
saveX = e.getX();
saveY = e.getY();
enemy.setCont(true);
move();
}
},100);
enemy.setOnWall(false);
}
}
But this code saves mouse coorinates immediately and then waits for 1000ms and I have old coordinates.