This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I feel like I should know why this is happening, but...
I am trying to show a simple animation when the user clicks a button. So I have a loop in the ActionPerformed method which calls repaint and then sleeps. But what happens is that only the last repaint actually happens. The other calls to repaint never seem to occur (that is, my System.out.println's don't come out).
All painting and event handling happens on one thread, the "Swing event thread." Until your event handler returns, repaint() calls result in paint requests being queued but not executed. You can't run your animation loop in an event handler: you should kick off a new thread from the handler, and run the loop in that new thread. This can be very simple to do -- i.e.,