I want to paint a panel blue, then wait five seconds, then do other stuff.
Now I have the following piece of code, which I expect to do what I want. Here it is:
JPanel somePanel = getSomePanel();
somePanel.setBackground(Color.BLUE);
Object lock = new Object();
synchronized (lock) {
try {
lock.wait(5000);
}
catch (InterruptedException exc) { }
}
// Do other stuff
But instead, it waits five seconds and then paints the component blue.
- Why first waiting, then painting blue, instead of vice versa? (I guess it has something to do with the Swing mechanism...?)
- How to 'change that order'?