File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Moving Circles Simultaneously Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
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: 3649
    
  17

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: 3649
    
  17

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: 19783
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Yep, but here it seems the movement isn't done in parallel.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Moving Circles Simultaneously