I have a piece of code in Java which draws 2 icons to the screen. I want to enforce a delay between them, and am unsure of the best way.
At the moment I have;
cell.setIcon(image1);
Thread.sleep(500); // Ignored try() for brevity
cell2.setIcon(image2);
But this seems to cause the delay before either are drawn. Why is this, and how can I fix it?
Assuming you’re using Swing, you need to cause the sleep to be performed on a worker thread, like so: