I want to add a delay in my program using the Thread.sleep(1000)
command (so making it stop for 1 second before continuing) but this means I also need to add the throws InterruptedException
. However, I'm not sure where to put it.
My code basically looks like this right now:
public static void main(String[] args) {
Clock myClock = new Clock; // new clock object.
while (true) {
myClock.tick();
}
}
My other class:
public class Clock {
// .. some constructors and stuff
public void tick() {
secondHand.draw(); // redraws the second hand to update every second
}
// .. some more methods and stuff
}
I want to only call the tick()
method every 1 second, but I don't know where I can put the Thread.sleep
and throws InterruptedException
statements. Any help would be appreciated. Also any input on other ways I can make my clock tick and/or update would be helpful too!