How to hide a popup after time elapses in Java/GWT [duplicate]
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.
精彩评论