Animation in Java

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.?

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

posted Jan 14, 2011 20:26:37

0

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