aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Animation in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Animation in Java" Watch "Animation in Java" New topic
Author

Animation in Java

chanakya nani
Greenhorn

Joined: Jan 11, 2011
Posts: 29
Hey Guys,

I'm encountering a small problem with the Class 'ForLoop' in the below code..

Desired Output: Oval moving down with changing colors.

The Output I'm getting: Oval staying in the first given co-ordinates and not moving and also not changing colors

If the for loop is used without the Object referencing, the code is working fine,but when i try to access the for loop through 'ForLoop' method i'm not getting the Animation..The Oval is Staying there itself(not moving).

Can anyone please tell me Why am i not getting the Desired Output. and what to do to get it.?


The Code is

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
OP, your code was very hard to read due to lack of formatting and misuse of code tags. Please review your post before finalizing it, and only paste already-formatted code. I have tried to fix your formatting and code tags. I will also move this thread to the Swing forum.

With regards to your question, your main issue is that you're calling Thread.sleep(...) on the EDT, the Swing event thread, and all this will do will be to put your application to sleep. Instead I recommend that you use a Swing Timer (javax.swing.Timer) to do your animation loop. The Swing tutorials will show you how to use this.
chanakya nani
Greenhorn

Joined: Jan 11, 2011
Posts: 29
pete stein wrote:OP, your code was very hard to read due to lack of formatting and misuse of code tags. Please review your post before finalizing it, and only paste already-formatted code. I have tried to fix your formatting and code tags. I will also move this thread to the Swing forum.

With regards to your question, your main issue is that you're calling Thread.sleep(...) on the EDT, the Swing event thread, and all this will do will be to put your application to sleep. Instead I recommend that you use a Swing Timer (javax.swing.Timer) to do your animation loop. The Swing tutorials will show you how to use this.



Thank you very much..I will definitely post better from on..As i am new here i am being accustomed to it...Sorry for the trouble..Thanks again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Animation in Java