Thread

run is called only once for a Thread of execution then how i can i create animtion if want to call run from paint method
[134 byte] By [ravin_patila] at [2007-10-2 12:35:45]
# 1

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.

dmbdmba at 2007-7-13 9:36:18 > top of Java-index,Core,Core APIs...
# 2
It looks like you're doing some sort of GUI work. In that case, you might have an easier time using the Timer class than doing your own threading
DaanSa at 2007-7-13 9:36:18 > top of Java-index,Core,Core APIs...
# 3

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.

__Dev-eloper__a at 2007-7-13 9:36:18 > top of Java-index,Core,Core APIs...
# 4

> 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

DaanSa at 2007-7-13 9:36:18 > top of Java-index,Core,Core APIs...