I'm trying to restrict the user from interacting with the program for a certain period of time, but sadly, with no success. I've tried using Thread.sleep
, but as soon as the sleep
action ends, the users' input catches up and keeps executing until it's finished.
For example, if I use the code below, the program will act as mentioned above: it'll sleep for the provided period of time (1,5s) and then the users' actions will catch up (it'll print "After waiting" as much times as the user clicked while the Thread.sleep
was active). So how would I prevent this? Any suggestions would be greatly appreciated.
public void mouseClicked(MouseEvent e) {
print();
}
public void print() {
System.out.println("After waiting.");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}