使用javafx淡入淡出场景中的多个图像

时间:2017-12-09 15:19:42

标签: javafx

我想在场景中淡出和淡出多张图像,但我得到的结果只是淡化了一张图像。

这是我的代码..提前感谢..

公共类MyFxTest扩展了Application {

public int count = 0;

@Override
public void start(Stage primaryStage) {

    //ImageView img = new ImageView("m.jpg");
    ArrayList<ImageView> img = new ArrayList<ImageView>();
    img.add(new ImageView("img1.jpg"));
    img.add(new ImageView("img2.jpeg"));
    img.add(new ImageView("img3.jpg"));
    img.add(new ImageView("img4.jpg"));
    img.add(new ImageView("img5.jpg"));
    img.add(new ImageView("img6.jpg"));
    img.add(new ImageView("img7.jpg"));
    img.add(new ImageView("img8.jpg"));
    img.get(count).setFitWidth(800);
    img.get(count).setFitHeight(500);

    Pane p = new Pane();
    FadeTransition ft = new FadeTransition(Duration.seconds(2),img.get(count));
    ft.setFromValue(1);
    ft.setToValue(0);
    ft.setAutoReverse(true);
    ft.setCycleCount(FadeTransition.INDEFINITE);
    ft.play();
    ft.setOnFinished(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            if (count >= img.size()) {
                count=0;
                ft.setNode(img.get(count));
            }else{
                count++;
                ft.setNode(img.get(count));
            }
        }
    });

    p.getChildren().add(img.get(count));
    Scene scene = new Scene(p, 800, 500);

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}

0 个答案:

没有答案