时间线javaFX线程

时间线javaFX线程,java,multithreading,javafx,timeline,Java,Multithreading,Javafx,Timeline,目前,我有一个图像列表,其中显示了一定时间的时间线。但是,我希望为每张图片设置一个计数器,即如果每张图片的时间为30秒,则应该在图片下方运行并显示倒计时?有没有办法实现这种行为 Image i1 = new Image(getClass().getResourceAsStream("IMG_YOGA/01.png"),200,200,false,false); Image i2 = new Image(getClass().getResourc

目前,我有一个图像列表,其中显示了一定时间的时间线。但是,我希望为每张图片设置一个计数器,即如果每张图片的时间为30秒,则应该在图片下方运行并显示倒计时?有没有办法实现这种行为

        Image i1 = new Image(getClass().getResourceAsStream("IMG_YOGA/01.png"),200,200,false,false);
        Image i2 = new Image(getClass().getResourceAsStream("IMG_YOGA/02.png"),200,200,false,false);
        Image i3 = new Image(getClass().getResourceAsStream("IMG_YOGA/03.png"),200,200,false,false);
        Image i4 = new Image(getClass().getResourceAsStream("IMG_YOGA/04.png"),200,200,false,false);
        Image i5 = new Image(getClass().getResourceAsStream("IMG_YOGA/05.png"),200,200,false,false);
        Image i6 = new Image(getClass().getResourceAsStream("IMG_YOGA/06.png"),200,200,false,false);
        Image i7 = new Image(getClass().getResourceAsStream("IMG_YOGA/07.png"),200,200,false,false);
        Image i8 = new Image(getClass().getResourceAsStream("IMG_YOGA/08.png"),200,200,false,false);

        Y_ImgView.setFitWidth(250);
        Y_ImgView.setFitHeight(300);
        
        final int NUM_FRAMES = 9;
        final int PAUSE_BETWEEN_FRAMES = 30;


        Timeline timeline = new Timeline();
        List<Image> images = List.of(i1,i2,i3,i4,i5,i6,i7,i8,i1);

        for (int i = 0; i < NUM_FRAMES; i++) {
            timeline.getKeyFrames().add(
                new KeyFrame(
                    javafx.util.Duration.seconds(i * PAUSE_BETWEEN_FRAMES), 
                    new KeyValue(Y_ImgView.imageProperty(), images.get(i))
                )
            );
        }

        timeline.setCycleCount(1);
        timeline.play();
        }
Image i1=新图像(getClass().getResourceAsStream(“IMG_瑜伽/01.png”),200200,false,false);
Image i2=新图像(getClass().getResourceAsStream(“IMG_YOGA/02.png”),200200,false,false);
Image i3=新图像(getClass().getResourceAsStream(“IMG_瑜伽/03.png”),200200,false,false);
Image i4=新图像(getClass().getResourceAsStream(“IMG_瑜伽/04.png”),200200,false,false);
Image i5=新图像(getClass().getResourceAsStream(“IMG_瑜伽/05.png”),200200,false,false);
Image i6=新图像(getClass().getResourceAsStream(“IMG_YOGA/06.png”),200200,false,false);
Image i7=新图像(getClass().getResourceAsStream(“IMG_瑜伽/07.png”),200200,false,false);
Image i8=新图像(getClass().getResourceAsStream(“IMG_瑜伽/08.png”),200200,false,false);
Y_ImgView.setFitWidth(250);
Y_ImgView.安装高度(300);
最终整数帧=9;
帧之间的最终整数暂停=30;
时间线=新时间线();
列表图像=列表(i1、i2、i3、i4、i5、i6、i7、i8、i1);
对于(int i=0;i
试试下面的方法

IntegerProperty countdown = new SimpleIntegerProperty();
Label countdownLabel = new Label();
countdownLabel.textProperty().bind(countdown.asString());

// add label to layout
然后

    Timeline timeline = new Timeline();
    List<Image> images = List.of(i1,i2,i3,i4,i5,i6,i7,i8,i1);

    for (int i = 0; i < NUM_FRAMES; i++) {
        timeline.getKeyFrames().add(
            new KeyFrame(
                javafx.util.Duration.seconds(i * PAUSE_BETWEEN_FRAMES), 
                new KeyValue(Y_ImgView.imageProperty(), images.get(i)),
                new KeyValue(countdown, 0),
                new KeyValue(countdown, PAUSE_BETWEEN_FRAMES)
            )
        );
    }
时间线=新时间线();
列表图像=列表(i1、i2、i3、i4、i5、i6、i7、i8、i1);
对于(int i=0;i
公开显示代码时,请遵守java命名约定非常感谢!!!!!我还有一个问题:当标签文本达到例如10秒时,我可以改变颜色或字体吗?如果是,我怎样做?Thanks@SomyaRathee是的,只需添加另一个
关键帧
即可更改颜色,并在重置倒计时时重新更改颜色。构造函数键值(ObjectProperty,color)未定义构造函数键值(ObjectProperty,color)未定义