开发者

How to hide a popup after time elapses in Java/GWT [duplicate]

开发者 https://www.devze.com 2023-01-26 15:38 出处:网络
This question already has answers here: 开发者_JAVA技巧 Closed 10 years ago. Possible Duplicate: How can we count the time of process?
This question already has answers here: 开发者_JAVA技巧 Closed 10 years ago.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消