0

I'm looking to call repaint() in my Java2D simulator at regular intervals.

What would be the best way to do this? Should I start another thread and have a loop that keeps track of currentTimeMillis()? Or is there a better way?

PhiLho
  • 40,535
  • 6
  • 96
  • 134
Scorcher84
  • 423
  • 1
  • 6
  • 9
  • 2
    Does your simulator need to 'simulate as fast as possible' or 'simulate at a fixed rate'? The answer may change how you structure this. – Tom Neyland Oct 19 '09 at 04:47

2 Answers2

2

Use timer function in java (javax.swing.Timer)

and this may useful for you efiicient way to repaint

ArK
  • 20,698
  • 67
  • 109
  • 136
1

Use a Timer. If its a Swing application use a Swing Timer. If its AWT then use TimerTask.

camickr
  • 321,443
  • 19
  • 166
  • 288