Javafx 2 JavaFX2动态点加载

Javafx 2 JavaFX2动态点加载,javafx-2,Javafx 2,我想创建一些加载点,如下所示: 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:

我想创建一些加载点,如下所示:

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...
依此类推,直到我关闭
阶段

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

我一直试图在这三个
文本之间创建一个循环:

Text dot = new Text("Loading.");
Text dotdot = new Text("Loading..");
Text dotdotdot = new Text("Loading...");
但是屏幕保持静止


如何在JavaFX中正确执行此操作?谢谢。

您是否考虑过使用进度指示器或进度条?我认为它们可以很好地解决显示动画和避免问题

我已经能够在JavaFX中完成它,不是通过动画,而是使用JavaFX中的并发类

我让你在这里输入代码。我觉得这不是很直观,因为我更喜欢进度指标。也许这不是最好的解决方案,但也许这会对你有所帮助


干杯

这个问题类似于:

这里有一个使用JavaFX的解决方案——对我来说,它似乎很简单,也不太复杂

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); }
}