Java中的javascript setTimeout相当于什么? [英] What is the equivalent of javascript setTimeout in Java?

查看:218
本文介绍了Java中的javascript setTimeout相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个函数,在单击按钮60秒后运行。请帮助,我使用Timer类,但我认为这不是最好的方法。

I need to implement a function to run after 60 seconds of clicking a button. Please help, I used the Timer class, but I think that that is not the best way.

推荐答案


我使用了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.

这篇关于Java中的javascript setTimeout相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆