aspose file tools
The moose likes Java in General and the fly likes Moving Circles Simultaneously Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Moving Circles Simultaneously " Watch "Moving Circles Simultaneously " New topic
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
    
    1

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
    
    1

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
    
    1

Yep, but here it seems the movement isn't done in parallel.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Moving Circles Simultaneously
 
Similar Threads
Make a class not to inherit and instantiate
Object that is Locked
Please help me complete steps to upload an image
A question about transaction and CRUD operations.
Question about Iterator Pattern ?