我试图在继续做下一件事之前添加延迟。这是我的代码:
private void startup() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
Platform.runLater(() -> {
mainPane.setBackground(new Background(new BackgroundFill(Color.rgb(28, 28, 28), null, null)));
logPane.setBackground(new Background(new BackgroundFill(Color.rgb(28, 28, 28), null, null)));
startupAnimation();
});
}
}, 3500);
logMessage(Mavis.LOG_INITIALIZE);
private void startupAnimation() {
FadeTransition ftMain = new FadeTransition(Duration.millis(1200), mainPane);
ftMain.setFromValue(0);
ftMain.setToValue(1);
ftMain.setCycleCount(1);
FadeTransition ftLog = new FadeTransition(Duration.millis(1200), logPane);
ftLog.setFromValue(0);
ftLog.setToValue(1);
ftLog.setCycleCount(1);
ParallelTransition pt = new ParallelTransition();
pt.getChildren().addAll(ftMain, ftLog);
TranslateTransition tt = new TranslateTransition(Duration.millis(800), mavisImgView);
tt.setByX(-210);
tt.setCycleCount(1);
FadeTransition ftOver = new FadeTransition(Duration.millis(1500), overlayPane);
ftOver.setFromValue(0);
ftOver.setToValue(1);
ftOver.setCycleCount(1);
SequentialTransition seq = new SequentialTransition(pt,tt, ftOver);
seq.play();
}
private void logMessage(String msg) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
Platform.runLater(() -> {
logTxtArea.setText(msg);
chatBalloon.setVisible(true);
});
}
}, 1500);
}
我想要实现的是,在记录消息之前,GUI必须启动3.5秒,然后在加载GUI时,它将记录消息。问题是该消息已经与GUI的启动一起记录,这似乎是什么问题?使用的计时器是java.util.Timer。