在JavaFX中为图像添加计时器

在JavaFX中为图像添加计时器,第1张

在JavaFX中为图像添加计时器

使用

Timeline
更新
imageProperty
ImageView

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4904959.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存