Java Swing GUI not updating
807600Oct 10 2007 — edited Oct 11 2007Hi there,
I want to program a little game consisting of catching figures with your mouse on a window.
I am adding the figures(squares, circles, etc) in a JPanel component at a fixed interval of time (say 600ms) and then remove them. Everything is ok if I call the "play" method within the main window constructor, but when I introduced a "new game" button, there is no figure showing up on the screen at the specified interval of time; all the figures show up at the end.
for example:
(for int 0=;i<10;++i)
{
mypanel.add(figure);
try{
Thread.sleep(600);
catch(Exception e){}
mypanel.remove(figure);
}
}
When I click the "play now" button, all 10 figures are visible after 6 second.
I guess the code is running in a separate thread and the GUI thread is not updated?
Thanks,
Iulian