[英]TimeLINE javaFX thread
At the moment I have a list with images which get displayed for a certain amount of time with a timeline.目前,我有一个图像列表,这些图像会在时间轴上显示一段时间。 However I want that a counter is set for each picture ie if the amount of time is 30 sec for each picture, there should be a countdown running and showing underneath the picture?
但是我希望为每张图片设置一个计数器,即如果每张图片的时间量为 30 秒,则应该有一个倒计时运行并显示在图片下方? Is there a way to achieve that behavior?
有没有办法实现这种行为?
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();
}
Try something like尝试类似的东西
IntegerProperty countdown = new SimpleIntegerProperty();
Label countdownLabel = new Label();
countdownLabel.textProperty().bind(countdown.asString());
// add label to layout
and then接着
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)
)
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.