In Java, I can use sleep(x)
to delay some code from running for x seconds. But, if I'm using Swing, that makes my GUI freeze, so it's not an ideal solution.
How can one create a delay before running a sequence of code in Java?
To start, you probably shouldn't be doing whatever you're doing in the display thread. If it were in your own thread, the GUI wouldn't freeze. But short of revisiting your entire thread strategy, the usual workaround is to add a queue of tasks to be run later.