What is the best way to call repaint() at regular intervals in my Java2D program?

柔情痞子 提交于 2020-01-06 07:17:17

问题


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?


回答1:


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

and this may useful for you efiicient way to repaint




回答2:


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



来源:https://stackoverflow.com/questions/1586984/what-is-the-best-way-to-call-repaint-at-regular-intervals-in-my-java2d-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!