aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Animation problem with swing 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 problem with swing" Watch "Animation problem with swing" New topic
Author

Animation problem with swing

Sean Panting
Greenhorn

Joined: Oct 13, 2010
Posts: 3
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!!!
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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!
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

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.
 
 
subject: Animation problem with swing