| Author |
Moving Circles Simultaneously
|
Mohamed Sedky
Greenhorn
Joined: Jun 15, 2011
Posts: 2
|
|
Hello all!
I want to move up to 10000 circle Simultaneously using Graphics abstract class and threads pooling if any idea please reply ASAP
Thanks ,
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3053
|
|
Hi Mohamed, welcome to CodeRanch!
Why do you want to use thread pools? You can easily do this with just the Event Dispatch Thread and a worker thread.
Start by writing a program that moves one circle around and draws it. One thread should be responsible for updating the location of the circle, and calling repaint() on the component used to draw the circle.
|
 |
Mohamed Sedky
Greenhorn
Joined: Jun 15, 2011
Posts: 2
|
|
this code runs but not Simultaneously" circle ends its moving and then another one starts . How can make it concurrent ??
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3053
|
|
Don't put program logic in the paintComponent method (I assume your painting method calls move, telling by the Graphics argument).
Use a separate thread to update the positions of the circles. SwingWorker may help you out.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
In the end you can't. The movement may be done in parallel, but the painting must still be done sequentially on the single Event Dispatcher Thread.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3053
|
|
|
Yep, but here it seems the movement isn't done in parallel.
|
 |
 |
|
|
subject: Moving Circles Simultaneously
|
|
|