This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 3574
    
  14

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: 3574
    
  14

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: 19649
    
  18

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: 3574
    
  14

Yep, but here it seems the movement isn't done in parallel.
 
 
subject: Moving Circles Simultaneously
 
Similar Threads
Question about Iterator Pattern ?
Please help me complete steps to upload an image
Object that is Locked
A question about transaction and CRUD operations.
Make a class not to inherit and instantiate