I want to do animation in Java. I have looked at: http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html
What I’m surprised by is that in the timer action handler:
- we do NOT do actually drawing function calls; we just update the state — so it appears the timer action is used for “simulation”
- we do a repaint request
- Swing repaints its request at its convenience
This seems somewhat odd to me because:
- Swing can collate multiple repaint requests into one
- if I’m counting fps in the timer, I can be over counting (since multiple repaints becomes one)
Question: am I mis reading the sample code, or is this the “correct” way to do animation in Java?
Thanks!
It’s fairly normal to do the state updates and rendering separately.
Java/Swing is pretty normal in this regard.
Reasons: