如何在 Java/GWT 中经过一段时间后隐藏弹出窗口

发布于 2024-10-04 00:28:57 字数 344 浏览 0 评论 0原文

可能的重复:
我们如何计算处理时间?

我有一个用户保存值后弹出的弹出对话框。我希望弹出窗口在 2 秒后消失。类似于

if(timeElapsed(2 seconds)){
    popup.hide()
}

我看到的相关问题衡量函数的运行时间。如何运行虚拟循环 2 秒,然后调用隐藏函数?

Possible Duplicate:
How can we count the time of process?

I have a pop-up dialog that pops up after a user had saved a value. I want the popup to disappear after 2 seconds. Somthing like

if(timeElapsed(2 seconds)){
    popup.hide()
}

The related questions I saw measure the running time of a function. How can I run a dummy loop for 2 seconds and then call the hide function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春如此纠结 2024-10-11 00:28:57

您可以在弹出面板中定义计时器。接下来,您可以在 show() 方法中初始化计时器,如下所示:

Timer t = new Timer() {
  public void run() {
    Popup.this.hide();
  }
}

t.schedule(2000);

这将在首次显示弹出窗口时启动计时器。当计时器到期时,弹出窗口将被隐藏。

最终,您可以将计时器定义为弹出窗口中的全局变量,并使用布尔值来查看计时器是否正在运行,这样,如果您需要在实例仍在显示时再次显示弹出窗口,则不会启动新的计时器。

You can define a Timer in your popup panel. Next you can init the Timer in the show() method like this:

Timer t = new Timer() {
  public void run() {
    Popup.this.hide();
  }
}

t.schedule(2000);

This will start the timer when the popup is first showed. When the timer expires, the popup will be hidden.

Eventually you can define the timer as a global variable in the popup and use a boolean to see if the timer is running, so that if you need to display the popup again while an instance is still showing, you won't start a new timer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文