Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Swing GUI not updating

807600Oct 10 2007 — edited Oct 11 2007
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 8 2007
Added on Oct 10 2007
5 comments
935 views