This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Swing problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing problems" Watch "Swing problems" New topic
Author

Swing problems

Eric Larsen
Ranch Hand

Joined: Mar 28, 2009
Posts: 35
The following code animates an oval from the top left to the bottom right of an inner class extended from JPanel. It draws and runs just fine, but then, when I click the button to redo the animation, it doesn't redraw/animate the panel. What am I doing wrong? Is it a bug or can I just not do this? Please see my other topic as well, javax.sound.midi problems, as it hasn't recieved any attention yet. Thanks in advance for the help.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
never have this type of code in Swing
Thread.sleep(50);

there is only a single thread in swing, and by 'sleeping' it, you also prevent it from repainting.
notice, when you click the button, it stays clicked for some seconds?

there are a number of ways to do your animation, simplest is using a swing.Timer
Eric Larsen
Ranch Hand

Joined: Mar 28, 2009
Posts: 35
Oh, ok thanks! I was trying to build on some sample code in Head First Java by adding a replay button to the animation, but I didn't know that the thread.sleep() would screw it up. Thank you again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing problems
 
Similar Threads
this animation code does not show o/p
help me it is a simple code but i need help
Inner classes in Eclipse
Event Problems: Need Help
cannot get the green circle to smear