且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java中的javascript setTimeout相当于什么?

更新时间:2022-03-13 04:23:20


我使用了Timer类,但我认为这不是***的方法。

"I used the Timer class, but I think that that is not the best way."

其他答案假设你是不使用Swing作为用户界面(按钮)。

The other answers assume you are not using Swing for your user interface (button).

如果您使用的是Swing,请执行使用 Thread。 sleep()因为它会冻结你的Swing应用程序。

If you are using Swing then do not use Thread.sleep() as it will freeze your Swing application.

相反你应该使用 javax.swing.Timer

参见Java教程如何使用Swing Timers 课程:Swing中的并发性以获取更多信息和示例。

See the Java tutorial How to Use Swing Timers and Lesson: Concurrency in Swing for more information and examples.