gpt4 book ai didi

javafx-2 - JavaFX 2 动态点加载

转载 作者:行者123 更新时间:2023-12-02 22:08:38 30 4
gpt4 key购买 nike

我想像这样创建一些加载点:

At 0 second the text on the screen is: Loading.
At 1 second the text on the screen is: Loading..
At 2 second the text on the screen is: Loading...
At 3 second the text on the screen is: Loading.
At 4 second the text on the screen is: Loading..
At 5 second the text on the screen is: Loading...

依此类推,直到我关闭 Stage

在 JavaFX 中最好/最简单的方法是什么?我一直在研究 JavaFX 中的动画/预加载器,但在尝试实现这一点时似乎很复杂。

我一直在尝试在这三个 Text 之间创建一个循环:

Text dot = new Text("Loading.");
Text dotdot = new Text("Loading..");
Text dotdotdot = new Text("Loading...");

但屏幕保持静止...

我怎样才能使它在 JavaFX 中正常工作?谢谢。

最佳答案

这个问题类似于:javafx animation looping .

这是一个使用 JavaFX 的解决方案 animation framework - 这对我来说似乎很简单,也不太复杂。

loading animation

import javafx.animation.*;
import javafx.application.Application;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;

/** Simple Loading Text Animation. */
public class DotLoader extends Application {
@Override public void start(final Stage stage) throws Exception {
final Label status = new Label("Loading");
final Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new EventHandler() {
@Override public void handle(Event event) {
String statusText = status.getText();
status.setText(
("Loading . . .".equals(statusText))
? "Loading ."
: statusText + " ."
);
}
}),
new KeyFrame(Duration.millis(1000))
);
timeline.setCycleCount(Timeline.INDEFINITE);

VBox layout = new VBox();
layout.getChildren().addAll(status);
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
stage.setScene(new Scene(layout, 50, 35));
stage.show();

timeline.play();
}

public static void main(String[] args) throws Exception { launch(args); }
}

关于javafx-2 - JavaFX 2 动态点加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15736082/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com