Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Animation in Java

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Men call me Jim. Women look past me to this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic