| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3278 人关注过本帖
标题:我想用JAVAFX 做一个简单GIF小动画,就是几张图片的转换,但我这样做一直错 ...
只看楼主 加入收藏
_涧边幽草
Rank: 1
等 级:新手上路
帖 子:24
专家分:2
注 册:2016-3-19
结帖率:25%
收藏
 问题点数:0 回复次数:1 
我想用JAVAFX 做一个简单GIF小动画,就是几张图片的转换,但我这样做一直错,不知道错哪里?暂时也没办法做出来?
我想用JAVAFX 做一个简单GIF小动画,就是几张图片的转换,
但我这样做一直错,不知道错哪里?暂时也没办法做出来?

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.scene.layout.Pane;
import javafx.util.Duration;
import javafx.scene.layout.StackPane;
import javafx.animation.FadeTransition;
import javafx.animation.Timeline;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.Pane;
import javafx.scene.image.ImageView;
import java.util.Timer;
import java.util.TimerTask;

public class Cartoon extends Application{

    @Override
    public void start(Stage stage){
        
        
        Pane pane=new StackPane();
        
        Image image1=new Image("image/111.jpg");
        ImageView imageView1=new ImageView(image1);
        imageView1.fitHeightProperty().bind(pane.heightProperty().divide(1));
        imageView1.fitWidthProperty().bind(pane.widthProperty().divide(1));
        
        Image image2=new Image("image/222.jpg");
        ImageView imageView2=new ImageView(image2);
        imageView2.fitHeightProperty().bind(pane.heightProperty().divide(1));
        imageView2.fitWidthProperty().bind(pane.widthProperty().divide(1));
        
        Image image3=new Image("image/333.jpg");
        ImageView imageView3=new ImageView(image3);
        imageView3.fitHeightProperty().bind(pane.heightProperty().divide(1));
        imageView3.fitWidthProperty().bind(pane.widthProperty().divide(1));
        
        Image image4=new Image("image/444.jpg");
        ImageView imageView4=new ImageView(image4);
        imageView4.fitHeightProperty().bind(pane.heightProperty().divide(1));
        imageView4.fitWidthProperty().bind(pane.widthProperty().divide(1));
        //----------------------------------------------------------------------
        ImageView[] imageView={imageView1,imageView2,imageView3,imageView4};
        CartoonPane cartoonPane=new CartoonPane(imageView);
        //----------------------------------------------------------------------
        FadeTransition ft1=new FadeTransition(Duration.millis(3000),imageView1);
        ft1.setCycleCount(Timeline.INDEFINITE);
        ft1.setFromValue(1.0);
        ft1.setToValue(0.1);
        ft1.setAutoReverse(true);
        ft1.play();
            
        FadeTransition ft2=new FadeTransition(Duration.millis(3000),imageView2);
        ft2.setCycleCount(Timeline.INDEFINITE);
        ft2.setFromValue(1.0);
        ft2.setToValue(0.1);
        ft2.setAutoReverse(true);
        ft2.play();
            
        FadeTransition ft3=new FadeTransition(Duration.millis(3000),imageView3);
        ft3.setCycleCount(Timeline.INDEFINITE);
        ft3.setFromValue(1.0);
        ft3.setToValue(0.1);
        ft3.setAutoReverse(true);
        ft3.play();
            
        FadeTransition ft4=new FadeTransition(Duration.millis(3000),imageView4);
        ft4.setCycleCount(Timeline.INDEFINITE);
        ft4.setFromValue(1.0);
        ft4.setToValue(0.1);
        ft4.setAutoReverse(true);
        ft4.play();
            
        pane.getChildren().add(cartoonPane);
        Scene scene=new Scene(pane,550,300);
        stage.setScene(scene);
        stage.setTitle("动画");
        stage.show();
        
    }
 
   
    public static void main(String[] args) {
        Application.launch(args);
    }
   
}


//下面是一个继承STACKPANE面板的自定义面板,主要是能传入一个图象显示数组,做成一个小动画
public class CartoonPane extends StackPane{
    private Pane pane=new StackPane();
    private ImageView[] imageView;
   
    public CartoonPane(ImageView[] imageView){
        
        this.imageView=imageView;
        Timer timer2=new Timer();
        timer2.schedule(new TimerTaskTest(imageView),0,1000);
        
    }
//继承TimerTask,TimerTaskTest作为一个内部类
    class TimerTaskTest extends TimerTask{
        ImageView[] imageView1;
        int i;
        
        public TimerTaskTest(ImageView[] imageView1){
            this.imageView1=imageView1;
            this.i=0;
            
        }
        
        @Override
        public void run(){
            //Date date1=new Date(this.scheduledExecutionTime());
            getChildren().clear();
            getChildren().add(this.imageView1[this.i++]);
            if(this.i>=4)//超过4,就令i变为0
                this.i=0;
        }
    }
}
搜索更多相关主题的帖子: import 图片 动画 
2016-11-04 00:09
_涧边幽草
Rank: 1
等 级:新手上路
帖 子:24
专家分:2
注 册:2016-3-19
收藏
得分:0 
希望各位大神帮我一下,不胜感激!
2016-11-04 00:10
快速回复:我想用JAVAFX 做一个简单GIF小动画,就是几张图片的转换,但我这样做一 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025938 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved