I am writing a game using Java Swing. I want to paint each time a loop executes with a small delay in between to create a cascade effect on screen. I believe that the effici
Not sure if I'm on the right track here, but is this a thread issue? Because the sleep will be putting the current thread to sleep. So if the repaint is on the current thread, you will be effectively queuing a repaint, holding, then queuing another repaint. Then the method ends and the event processing loop of the graphics thread fires, executing two repaints (collapsed) making everything happen at once.
Based on that thought I think you might have two options:
Put the code on a second thread so that it doesn't halt the main graphics thread and also because it means that the graphics thread cando a repaint along side the sleep happening.
Before you sleep (not really recommended I would think), trigger the event loop to force the repaint to happen. I'd have to look this up. Cannot remember how to do it off the top of my head. :-)
I'd probably be looking at #1 as the best option.