Win a copy of Testing JavaScript Applications 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Animation problem with swing

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create an applet of a rain storm. i've already have the program working, pretty much. the only problem that i have is... well let me explain it this way: RainDrop is the class that has the methods to draw the raindrop to the screen, move it down the screen, and destroy it when it reaches the bottom of the frame. (Note: if you want 20 raindrops on the screen, you need 20 instances of RainDrop by the way i have it setup.) each instance of RainDrop implements Runnable. the run methods of each class will paint a blue oval to the screen, move the coordinates down, then call repaint(). this paints to an image, ALL instances of raindrop paint to one image, then the call to paint well paints that image onto the frame, double buffering it. the problem i'm having is the stupid Thread system in java. here's an example of what i mean: 2 instances of raindrop are in the part of the thread sequence where it paints the raindrop to the screen. well, at the same time, another instance of raindrop is executing the command to draw a rectangle the size of the screen, to cover up the other traces of the left behinds raindrop images, making the raindrops look animated. what i'm basically getting at is that because of this system, the final result is that the raindrops flicker all the way down the screen, and i'm pretty sure that sun has created a class or a method that i have not seen yet that will take care of this problem. PLEASE HELP!!!
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and welcome to the Ranch!

You may want to post some code so we can see what you're doing. Also, is this Swing -- are you using a JApplet and drawing in a JPanel? Does each Raindrop call repaint? ... your code will likely answer most of our questions.

Best of luck and again, welcome!
 
Saloon Keeper
Posts: 12161
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if I would use a thread for each rain drop. Use a draw loop in the main thread instead, and use it to iterate over all rain drops.
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic