The code you're running is running in the Event Dispatcher
Thread. This is also the same thread that will do the painting - but only after an event is completely handled. Therefore,
you should never ever but lengthy operations in event handlers.
You'll need to create a new Thread which will do the loop for you, and then wrap the calls to repaint in EventQueue.invokeLater.
Alternatively, you can check out SwingWorker:
How this works:
- worker.execute() creates a new Thread that executes doInBackground.
- publish takes the arguments, puts them in a List, and then makes sure process is called on the Event Dispatch Thread.
- when doInBackground is finished, done() is called on the Event Dispatch Thread again. This can be used to finish things up if needed.
So just call this code in your actionPerformed method, and it should work.
Also, Campbell is right about the sleep time. You have specified 1ms, whereas the human eye can only process around 24 frames per second (I believe). So everything below 40 will be hard to notice. You could still go for something lower but I wouldn't go below 20.
[ August 31, 2008: Message edited by: Rob Prime ]