预加载器的handleStateChangeNotification函数

时间:2018-09-13 18:06:03

标签: javafx

我正在尝试向我的preloader类中添加FadeTransition,所以preloader和主应用程序之间的过渡更加顺畅。
如果我使用的是预加载器的handleStateChangeNotification方法,则渐变不会运行,并且预加载器保持打开状态。

@Override
public void handleStateChangeNotification(StateChangeNotification stateChangeNotification) {
    if (stateChangeNotification.getType() == StateChangeNotification.Type.BEFORE_START) {
        FadeTransition fadeTransition = new FadeTransition(Duration.millis(2000));
        fadeTransition.setNode(preloaderStage.getScene().getRoot());
        fadeTransition.setFromValue(1.0);
        fadeTransition.setToValue(0.0);
        fadeTransition.setOnFinished(event ->
                preloaderStage.close());
        fadeTransition.play();
    }
}

我调试了代码,并调用了fadeTransition.play(),但是没有调用setOnFinished事件,因此预加载器也保持打开状态。

如果我将相同的代码添加到handleApplicationNotification方法中,它将完美运行。淡入淡出,舞台被正确关闭:

@Override
public void handleApplicationNotification(PreloaderNotification info) {
    if (info instanceof Preloader.ProgressNotification) {
        preloaderController.getProgressBar().setProgress(((Preloader.ProgressNotification) info).getProgress());
        if (preloaderController.getProgressBar().getProgress() == 1.0) {
            FadeTransition fadeTransition = new FadeTransition(Duration.millis(2000));
            fadeTransition.setNode(preloaderStage.getScene().getRoot());
            fadeTransition.setFromValue(1.0);
            fadeTransition.setToValue(0.0);
            fadeTransition.setOnFinished(event ->
                    preloaderStage.close());
            fadeTransition.play();
        }
    }
}

我的问题是:为什么不从handleStateChangeNotification开始播放过渡。

0 个答案:

没有答案