Thread.sleep 后 Java GUI 未启动

我试图在满足某个条件时弹出一个窗口,但是当满足条件时。窗口没有打开。我正在使用 Thread.sleep


代码:


public void grow() {

    Thread thread = new Thread(() -> {

        try {

            Thread.sleep(this.harvestTime);

            if(water >= waterNeeded && fertelizer >= fertelizerNeeded) {

                this.harvest = true;

                AlertBox.display("CROP ALERT","A SEED HAS FINISHED GROWING");

                Thread.sleep(60000);

                if(harvest == true) {

                    withered = true;

                    harvest = false;

                    AlertBox.display("ALERT", "FAILED TO HARVEST A CROP. IT BECAME WITHERED!");

                }

            }

            else {

                this.withered = true;

            }

        } catch (Exception e) {

        }

    });

    thread.start();

}


ITMISS
浏览 160回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java