Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为javafx中的图像添加计时器_Java_Javafx - Fatal编程技术网

为javafx中的图像添加计时器

为javafx中的图像添加计时器,java,javafx,Java,Javafx,我想在javafx中为我的图像添加计时器,例如,首先,我的第一个图像显示约3秒,然后我的第二个图像显示约5秒,然后什么也不显示。对此有何想法?使用更新的图像属性: 谢谢。另一个问题是,如何在每个持续时间内添加2个图像?只需在每个关键帧中为其imageProperty创建一个额外的ImageView和一个KeyValue。(关键帧构造函数接受任意数量的关键帧(Duration.ZERO、new KeyValue(imageView.imageProperty()、image1)、new KeyVa

我想在javafx中为我的图像添加计时器,例如,首先,我的第一个图像显示约3秒,然后我的第二个图像显示约5秒,然后什么也不显示。对此有何想法?

使用更新的
图像属性


谢谢。另一个问题是,如何在每个持续时间内添加2个图像?只需在每个关键帧中为其
imageProperty
创建一个额外的
ImageView
和一个
KeyValue
。(关键帧构造函数接受任意数量的关键帧(Duration.ZERO、new KeyValue(imageView.imageProperty()、image1)、new KeyValue(imageViewAdditional.imageProperty()、image2)),-我添加了这个,但显示了第一个图像如何在图像之间添加淡入过渡?创建附加的
关键帧
s和
KeyValue
s来操纵图像视图的不透明度属性。
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class ImageDisplayTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        Image image1 = new Image("...") ;
        Image image2 = new Image("...")  ;
        ImageView imageView = new ImageView();
        Timeline timeline = new Timeline(
                new KeyFrame(Duration.ZERO, new KeyValue(imageView.imageProperty(), image1)),
                new KeyFrame(Duration.seconds(3), new KeyValue(imageView.imageProperty(), image2)),
                new KeyFrame(Duration.seconds(8), new KeyValue(imageView.imageProperty(), null))
                );
        timeline.play();
        StackPane root = new StackPane();
        root.getChildren().add(imageView);
        primaryStage.setScene(new Scene(root, 800, 600));
        primaryStage.show();
    }

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