How can we count the time of process?

2020-04-02 09:38发布

I created a PopupPanel and have shown it. I want to hide it after one minute has passed. During that one minute, the process should not be stopped or paused. How can I achieve this behavior?

标签: gwt timer popup
3条回答
老娘就宠你
2楼-- · 2020-04-02 10:14

You could use Thread.sleep(60000);

But be careful you have to chose the correct thread to pause. And exception handling also has to be added.

查看更多
叼着烟拽天下
3楼-- · 2020-04-02 10:37

Try to use: java.util.Timer

And you can do something like this:

int seconds = 60;
Timer timer = new Timer();
timer.schedule(new YourScheduledTask(), seconds * 1000);

Exmaple: Use java.util.Timer to schedule a task to execute once 5 seconds have passed

查看更多
女痞
4楼-- · 2020-04-02 10:38

GWT has its own implementation of Timer.

Here a really small example:

public void onModuleLoad() {
    final PopupPanel popUp = new PopupPanel();
    Label text = new Label("gone in a sec");
    popUp.setWidget(text);

    Timer timer = new Timer() {

        @Override
        public void run() {
            popUp.hide();
        }

    };

    popUp.center();
    timer.schedule(3000);
}
查看更多
登录 后发表回答