you probably shouldn't call run from the paint method. In fact you shouldn't call run at all.
you should call .start() on the thread, somewhere else in the class. Perhaps in an beginAnimation() method that you write, or something.
The run method, then, should adjust some values, and call repaint(). The paintComponent method should then use those values to redraw the item.
Isn't Paint method called continuously from a loop ( in which parameters to paint method get changed, to paing different picture , as per animation logic or user input).
If that is so then , you can always create thread in paint but it wont be thread safe.It might happen thread created in previous Paint method call might clash with thread in the current one.
You will have to synchronize them. and if you are to synchronize them there wont be much performance gain or use creating threads.
Please let me know if i am wrong.
> Please let me know if i am wrong.
Yes you are.
> Isn't Paint method called continuously from a loop (
> in which parameters to paint method get changed, to
> paing different picture , as per animation logic or
> user input).
paint is not called continously, but it is called often. It does get a parameter with various graphics properties, but they have nothing to do with either animation logic or user input
> If that is so then , you can always create thread in
> paint but it wont be thread safe.It might happen
> thread created in previous Paint method call might
> clash with thread in the current one.
I have no idea what this is supposed to mean. But generally, don't start threads in paint(). In almost all cases it's better to start them in event handlers
> You will have to synchronize them. and if you are to
> synchronize them there wont be much performance gain
> or use creating threads.
Yes there will be. Because trying to do animation without threads is going to fail. Miserably. You'll almost always need one thread to deliver events and repaint the components while another one (or a dozen) are doing animation.
Technically speaking, it is possible to animate in a paint method without using threading. But it'll be very, very unreliable. And quite likely hell to debug