我正在制作一个程序,其中有3个图像,并通过幻灯片显示每个图像显示两秒钟 . 我的秒数与目前的秒数不同 . 但是我的代码行声明KeyFrame有问题 . 我把所有代码都放在下面 . 关于我应该用关键帧或我的代码中的其他任何内容更改的建议 . 这是使用JavaFX .
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package digitalpictureframe;
import java.io.File;
//import java.time.Duration;
import java.util.Arrays;
import javafx.util.Duration;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author Zachary Murphy
*/
public class DigitalPictureFrame extends Application {
@Override
public void start(Stage primaryStage) {
Image image1 = new Image("1.png");
Image image2 = new Image("2.png");
Image image3 = new Image("3.png");
ImageView imageView = new ImageView();
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(imageView.imageProperty(), image1)),
new KeyFrame(Duration.seconds(1), new KeyValue(imageView.imageProperty(), image2)),
new KeyFrame(Duration.seconds(2), new KeyValue(imageView.imageProperty(), image3)),
new KeyFrame(Duration.seconds(4), 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);
}
}v
1 回答
以下代码用于图像幻灯片 . 它循环显示25个图像并单击暂停,然后再次单击再次启动 . 我还在图像之间使用了淡入淡出动画 . 每张图片将保留2秒钟 .