簡體   English   中英

如何停止thread.sleep停止整個JFrame

[英]How to stop thread.sleep from stopping entire JFrame

這可能是一個快速且新手的修復程序,但我現在很絕望。 當我使用Thread.sleep時,它將停止整個JFrame,對此是否有快​​速解決方法?

樣例代碼

public  void delay() throws InterruptedException {
    //Construct to create a delay.  
    Thread.sleep (30);
}

如果只是要實現的延遲,那么javax.swing.Timer是一個不錯的選擇。 您可以這樣使用它:

    public void delay(){
        Timer timer = new Timer(30, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                //do stuff after delay
            }
        });
        timer.start();
    }

如果顯示更多代碼,則可能會得到改善。 您可以在此處找到教程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM