This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Animation in Java

 
chanakya nani
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic