Simple animation using Thread.sleep() in ActionListener

人走茶凉 提交于 2019-11-28 02:16:33

Swing is a single threaded environment, anything that blocks the Event Dispatching Thread, will prevent it from been able to process new events, including, paint events.

The use of Thread.sleep within the actionPerformed method is blocking the EDT, preventing it from processing new events, including paint events, until the actionPerformed method is exited.

You should use a javax.swing.Timer instead.

Take a look at Concurrency in Swing and How to Use Swing Timers for more details

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