JavaFX:单击按钮后,如何执行代码行,然后执行thread.sleep x秒,然后运行其余代码

时间:2020-05-04 06:52:35

标签: javafx javafx-8

在JavaFX上,单击按钮后,我想运行一些代码行,等待x秒钟,然后完成剩余的代码。这就是我尝试过的。

        /* On button click */
    buttonD.setOnAction(action -> {

        /* Gets text from text field */
        String text = input.getText();

        /* Some alteration to the text from another class */
        CaesarCipher obj = new CaesarCipher();
        String varD = obj.decrypt(text, 10);

        /* Changes what was in the text field, to the altered text */
        input.setText(varD + "\n");

        /* Wait 10 seconds */
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        /* After 10 seconds, clear the text field*/
        input.clear();

    });

问题是,一旦我单击按钮,它将自动开始倒计时,然后向下以清除文本字段,而不是先更改文本字段内的文本,然后等待x秒,最后清除文本字段。

0 个答案:

没有答案
相关问题