Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Moving Circles Simultaneously

 
Mohamed Sedky
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this code runs but not Simultaneously" circle ends its moving and then another one starts . How can make it concurrent ??
 
Stephan van Hulst
Bartender
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stephan van Hulst
Bartender
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, but here it seems the movement isn't done in parallel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic