本代码需要配置javafx后即可使用,Javafx配置可以参考百度。

在Eclipse下运行程序,自己下载图片更改代码中图片的位置和照片名即可。

 代码如下

import javafx.animation.Animation;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import java.io.File;
import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.PathTransition;
import javafx.animation.SequentialTransition;
import javafx.animation.Timeline;
import javafx.util.Duration;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Line;
import javafx.application.Application;
import javafx.embed.swing.JFXPanel;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.stage.Stage;
import  javafx.scene.layout.*;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import  javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import  javafx.scene.shape.Circle;
import  javafx.scene.text.*;
import  javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.embed.swing.JFXPanel;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import java.io.File;public class Testtest extends Application{@Override                                  //主类重写了Application类中start方法,当javafx启动时使用无参构造方法来创建类的一个实例并调用start方法public void start(Stage primaryStage) {Pane pane=new Pane();             //布局面板ImageView imageView1=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\a.png");pane.getChildren().add(imageView1);FadeTransition A=new FadeTransition(Duration.millis(8000),imageView1);          //图片在面板中消失A.setFromValue(0);A.setToValue(1.0);A.setAutoReverse(true);A.play();     Text texta=new Text(10,40,"准备好了吗?孩子们? ");texta.setFill(Color.BLACK);texta.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,150));           //设置字体大小pane.getChildren().add(texta);PathTransition  aa=new PathTransition(Duration.millis(4000),new Line( -100,800, 800,800),texta);    //将文字放入面板中aa.setCycleCount(1);aa.play();FadeTransition aaa=new FadeTransition(Duration.millis(6000),texta);          //文字在面板中消失aaa.setFromValue(1.0);aaa.setToValue(0);aaa.setAutoReverse(true);aaa.play();        //           图片二ImageView imageView2=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\b.jpg ");pane.getChildren().add(imageView2);PathTransition  b=new PathTransition(Duration.millis(10000),new Line( -8000,300, 800,300),imageView2);    //将图片放入面板中b.setCycleCount(1);b.play();FadeTransition B=new FadeTransition(Duration.millis(5500),imageView2);          //图片在面板中消失B.setFromValue(0);B.setToValue(1);B.setAutoReverse(true);B.play();  Text textb=new Text(10,50,"HI,派大星");textb.setFill(Color.BLACK);textb.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,150));           //设置字体大小pane.getChildren().add(textb);PathTransition  bb=new PathTransition(Duration.millis(11000),new Line( -10000,800, 800,800),textb);    //将文字放入面板中bb.setCycleCount(1);bb.play();FadeTransition bbb=new FadeTransition(Duration.millis(20000),textb);          //文字在面板中消失bbb.setFromValue(1.0);bbb.setToValue(0);bbb.setAutoReverse(true);bbb.play();        //图片3ImageView imageView3=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\c.jpg ");pane.getChildren().add(imageView3);PathTransition  c=new PathTransition(Duration.millis(17000),new Line( 10000,300, 800,300),imageView3);    //将图片放入面板中c.setCycleCount(1);c.play();Text textc=new Text(10,50,"派大星,你为什么叫派大星? ");textc.setFill(Color.BLACK);textc.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,150));           //设置字体大小pane.getChildren().add(textc);PathTransition  cc=new PathTransition(Duration.millis(15000),new Line( -50000,800, 1000,800),textc);    //将文字放入面板中cc.setCycleCount(1);cc.play();FadeTransition ccc=new FadeTransition(Duration.millis(25000),textb);          //文字在面板中消失ccc.setFromValue(1.0);ccc.setToValue(0);ccc.setAutoReverse(true);ccc.play();       //图4ImageView imageView4=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\d.jpg ");pane.getChildren().add(imageView4);PathTransition  d=new PathTransition(Duration.millis(20000),new Line( 1200,-80000, 950,620),imageView4);    //将图片放入面板中d.setCycleCount(1);d.play();Text textd=new Text(10,50,"因为我是上帝派来保护你的大星星 ");textd.setFill(Color.BLACK);textd.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,110));           //设置字体大小pane.getChildren().add(textd);PathTransition  dd=new PathTransition(Duration.millis(20000),new Line( -80000,800, 950,800),textd);    //将文字放入面板中dd.setCycleCount(1);dd.play();FadeTransition ddd=new FadeTransition(Duration.millis(50000),textd);          //文字在面板中消失ddd.setFromValue(1.0);ddd.setToValue(0);ddd.setAutoReverse(true);ddd.play();       //图5ImageView imageView5=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\e.jpg ");pane.getChildren().add(imageView5);PathTransition  e=new PathTransition(Duration.millis(23000),new Line( 1200,80000, 950,620),imageView5);    //将图片放入面板中e.setCycleCount(1);e.play();Text texte=new Text(10,50,"嗯....我简直不敢相信我的耳朵!  ");texte.setFill(Color.BLACK);texte.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,110));           //设置字体大小pane.getChildren().add(texte);PathTransition  ee=new PathTransition(Duration.millis(23000),new Line( -80000,800, 950,800),texte);    //将文字放入面板中ee.setCycleCount(1);ee.play();FadeTransition eee=new FadeTransition(Duration.millis(50000),texte);          //文字在面板中消失eee.setFromValue(1.0);eee.setToValue(0);eee.setAutoReverse(true);eee.play();     //图6ImageView imageView6=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\f.jpg ");pane.getChildren().add(imageView6);PathTransition  f=new PathTransition(Duration.millis(27000),new Line( 1200,80000, 950,620),imageView6);    //将图片放入面板中f.setCycleCount(1);f.play();Text textf=new Text(10,50,"你怎么可能相信,因为你根本就没有耳朵  ");textf.setFill(Color.BLACK);textf.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(textf);PathTransition  ff=new PathTransition(Duration.millis(28000),new Line( 80000,800, 800,800),textf);    //将文字放入面板中ff.setCycleCount(1);ff.play();FadeTransition fff=new FadeTransition(Duration.millis(70000),textf);          //文字在面板中消失fff.setFromValue(1.0);fff.setToValue(0);fff.setAutoReverse(true);fff.play();       //图7ImageView imageViewg=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\g.jpeg ");pane.getChildren().add(imageViewg);PathTransition  g=new PathTransition(Duration.millis(30000),new Line( 1200,80000, 950,620),imageViewg);    //将图片放入面板中g.setCycleCount(1);g.play();Text textg=new Text(10,50,"嗨,海绵宝宝,我们去抓水母吧  ");textg.setFill(Color.BLACK);textg.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(textg);PathTransition  gg=new PathTransition(Duration.millis(30000),new Line( -75000,100, 950,100),textg);    //将文字放入面板中gg.setCycleCount(1);gg.play();FadeTransition ggg=new FadeTransition(Duration.millis(45000),textg);          //文字在面板中消失ggg.setFromValue(1.0);ggg.setToValue(0);ggg.setAutoReverse(true);ggg.play();      //图8//图7ImageView imageViewh=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\h.gif ");pane.getChildren().add(imageViewh);PathTransition  h=new PathTransition(Duration.millis(32000),new Line( 1200,75000, 950,620),imageViewh);    //将图片放入面板中h.setCycleCount(1);h.play();Text texth=new Text(10,50,"今天不行,我要上学  ");texth.setFill(Color.BLACK);texth.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(texth);PathTransition  hh=new PathTransition(Duration.millis(32000),new Line( 80000,800, 800,800),texth);    //将文字放入面板中hh.setCycleCount(1);hh.play();//图8ImageView imageViewi=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\c.jpg ");pane.getChildren().add(imageViewi);PathTransition  i=new PathTransition(Duration.millis(36000),new Line( 1200,75000, 950,620),imageViewi);    //将图片放入面板中i.setCycleCount(1);i.play();Text texti=new Text(10,50,"一般我不在家的时候,你都干些什么啊   ");texti.setFill(Color.BLACK);texti.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(texti);PathTransition  ii=new PathTransition(Duration.millis(36000),new Line( 85000,800, 800,800),texti);    //将文字放入面板中ii.setCycleCount(1);ii.play();FadeTransition iii=new FadeTransition(Duration.millis(45000),texti);          //文字在面板中消失iii.setFromValue(1.0);iii.setToValue(0);iii.setAutoReverse(true);iii.play();    //图9ImageView imageViewj=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\j.gif");pane.getChildren().add(imageViewj);PathTransition  j=new PathTransition(Duration.millis(38000),new Line( 1200,105000, 950,620),imageViewj);    //将图片放入面板中j.setCycleCount(1);j.play();Text textj=new Text(10,50,"等你回来   ");textj.setFill(Color.BLACK);textj.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(textj);PathTransition  jj=new PathTransition(Duration.millis(38000),new Line( 95000,800, 800,800),textj);    //将文字放入面板中jj.setCycleCount(1);jj.play();//图10ImageView imageViewk=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\k.jpeg");pane.getChildren().add(imageViewk);PathTransition  k=new PathTransition(Duration.millis(42500),new Line( 1200,-85000, 950,680),imageViewk);    //将图片放入面板中k.setCycleCount(1);k.play();//11ImageView imageViewl=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\l.gif");pane.getChildren().add(imageViewl);PathTransition  l=new PathTransition(Duration.millis(44500),new Line( 1200,85000, 1300,820),imageViewl);    //将图片放入面板中l.setCycleCount(1);l.play();//12ImageView imageViewm=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\j.gif");pane.getChildren().add(imageViewm);PathTransition  m=new PathTransition(Duration.millis(44500),new Line( 1200,85000, 400,820),imageViewm);    //将图片放入面板中m.setCycleCount(1);m.play();Text textm=new Text(10,50,"HI.章鱼哥   ");textm.setFill(Color.BLACK);textm.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(textm);PathTransition  mm=new PathTransition(Duration.millis(46500),new Line( 100000,800, 800,800),textm);    //将文字放入面板中mm.setCycleCount(1);mm.play();FadeTransition mmm=new FadeTransition(Duration.millis(69000),textm);          //文字在面板中消失mmm.setFromValue(1.0);mmm.setToValue(0);mmm.setAutoReverse(true);mmm.play();    //13ImageView imageViewn=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\n.gif");pane.getChildren().add(imageViewn);PathTransition n=new PathTransition(Duration.millis(49500),new Line( 1200,-85000, 700,200),imageViewn);    //将图片放入面板中n.setCycleCount(1);n.play();Text textn=new Text(10,50,"吵什么!还让不让人睡觉了。");textn.setFill(Color.BLACK);textn.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(textn);PathTransition nn=new PathTransition(Duration.millis(51000),new Line( -75000,800, 1200,400),textn);    //将文字放入面板中nn.setCycleCount(1);nn.play();FadeTransition nnn=new FadeTransition(Duration.millis(72000),textn);          //文字在面板中消失nnn.setFromValue(1.0);nnn.setToValue(0);nnn.setAutoReverse(true);nnn.play(); Text textnh=new Text(10,50,"你想要吹泡泡吗,只要两毛五");textnh.setFill(Color.BLACK);textnh.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,80));           //设置字体大小pane.getChildren().add(textnh);PathTransition nnh=new PathTransition(Duration.millis(55000),new Line( 92000,800, 800,960),textnh);    //将文字放入面板中nnh.setCycleCount(1);nnh.play();//14ImageView imageView14=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\c.jpg ");pane.getChildren().add(imageView14);PathTransition  c14=new PathTransition(Duration.millis(75000),new Line( 10000,500, 950,500),imageView14);    //将图片放入面板中c14.setCycleCount(1);c14.play();Text textnh14=new Text(10,50,"知识代表不了友谊,所以我宁愿做一个笨蛋也不愿意失去你");textnh14.setFill(Color.BLACK);textnh14.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,40));           //设置字体大小pane.getChildren().add(textnh14);PathTransition nnh14=new PathTransition(Duration.millis(79000),new Line( -92000,800, 800,960),textnh14);    //将文字放入面板中nnh14.setCycleCount(1);nnh14.play();Scene scene=new Scene(pane);primaryStage.setTitle("ShowImage");primaryStage.setScene(scene);primaryStage.show();}public static void main(String[] args){
//      程序外的本地文件应该使用URI地址//   File f = new File("G:\\音乐\\翻唱\\1.mp3");//C:\Users\lenovo\Music\联想安卓音乐File f = new File("C:\\Users\\lenovo\\Music\\联想安卓音乐\\a.mp3");Media _media = new Media(f.toURI().toString());final JFXPanel fxPanel = new JFXPanel();MediaPlayer _mediaPlayer = new MediaPlayer(_media);_mediaPlayer.play();Application.launch(args);}

注意:只需更改图片所在位置,就可以自行更换画面。
主要代码,其余都是改变照片名称来实现照片的更替


ImageView imageView1=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\a.png");pane.getChildren().add(imageView1);FadeTransition A=new FadeTransition(Duration.millis(8000),imageView1);          //图片在面板中消失A.setFromValue(0);A.setToValue(1.0);A.setAutoReverse(true);A.play();        Text texta=new Text(10,40,"准备好了吗?孩子们? ");texta.setFill(Color.BLACK);texta.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,150));           //设置字体大小pane.getChildren().add(texta);PathTransition  aa=new PathTransition(Duration.millis(4000),new Line( -100,800, 800,800),texta);    //将文字放入面板中aa.setCycleCount(1);aa.play();FadeTransition aaa=new FadeTransition(Duration.millis(6000),texta);          //文字在面板中消失aaa.setFromValue(1.0);aaa.setToValue(0);aaa.setAutoReverse(true);aaa.play();

创建一个ImageView对象:用来插入图片。并将图片放入Pane()面板中。
一定要放入面板pane()中才能显示图片。

ImageView imageView1=new ImageView("file:C:\\\\Users\\lenovo\\Pictures\\Saved Pictures\\a.png");
pane.getChildren().add(imageView1);

FadeTransition()用来设置对象透明度,在Duration.millis()中可以设置渐入渐出时间,下图中设置的是8000毫秒,也就是8秒。
A.setFromValue(0);是初始透明度是0;
A.setToValue(1.0);是结束时透明度为1.也就是在8秒内桌面会由无到有产生一个图片。

FadeTransition A=new FadeTransition(Duration.millis(8000),imageView1);          //图片在面板中消失A.setFromValue(0);A.setToValue(1.0);A.setAutoReverse(true);A.play();

Text类用来设置字幕。 texta.setFill(Color.BLACK);设置字体颜色,texta.setFont(Font.font(“Courier”,FontWeight.BOLD,FontPosture.ITALIC,150));设置字体大小,一定要有 pane.getChildren().add(texta);才能在画面中出现字幕。
PathTransition aa=new PathTransition(Duration.millis(4000),new Line( -100,800, 800,800),texta); 设置字幕移动。

 Text texta=new Text(10,40,"准备好了吗?孩子们? ");texta.setFill(Color.BLACK);texta.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.ITALIC,150));           //设置字体大小pane.getChildren().add(texta);PathTransition  aa=new PathTransition(Duration.millis(4000),new Line( -100,800, 800,800),texta);    //将文字放入面板中aa.setCycleCount(1);aa.play();

背景音乐:只需将下列代码复制粘贴,然后提前下载音乐。改名音乐地址。
File f = new File(“C:\Users\lenovo\Music\联想安卓音乐\a.mp3”);

   File f = new File("C:\\Users\\lenovo\\Music\\联想安卓音乐\\a.mp3");Media _media = new Media(f.toURI().toString());final JFXPanel fxPanel = new JFXPanel();MediaPlayer _mediaPlayer = new MediaPlayer(_media);_mediaPlayer.play();

java代码制作动画相关推荐

  1. 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果

    AlphaAnimation 透明效果实现: activity_main.xml中仅仅是一个简单的图片,下面的例子都会使用这个xml: <RelativeLayout xmlns:android ...

  2. java运用ascii实现动画效果_安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果...

    AlphaAnimation 透明效果实现: activity_main.xml中仅仅是一个简单的图片,下面的例子都会使用这个xml: xmlns:tools="http://schemas ...

  3. 如何将写好的java代码制作成镜像,并上传到镜像仓库

    学习docker已经有三个月了,之前总是一股脑的学,没有静下心来做整理,现在终于有时间可以好好整理三个月的学习成果了,今天就整理一下如何将写好的代码制作成镜像并将镜像上传到代码仓库. 1.代码编写 本 ...

  4. java代码制作activiti会签_工作流 activiti 自定义下一审批人和多人会签的简单实现...

    1.动态指定下一审批人 在这里我使用的是监听器模式 首先看整体的流程图 在需要动态指定审批人的节点上添加一个任务监听器 这是已经添加好的监听器 选择create  然后将需要使用的监听器路径写上. j ...

  5. Java语言制作动画

    为了使制作出来的满天星更加好看,采用随机数产生,对于产生的位置采用二维数组进行定义. 为了使动画动起来,通过改变横纵坐标的大小来实现(写这篇的目的是为了证明Java不是枯燥无味的) import ja ...

  6. 使用Java代码制作二维码(超级简单)

    操作步骤 真的是灰常简单,导入三个jar包,十几行代码就搞定了. 源代码和jar包已经打包放在阿里云盘里面,文末有链接. import com.google.zxing.BarcodeFormat; ...

  7. java可以制作动画么,Java:如何避免仅制作形状的动画(没有图像...

    嗨,我正在阅读Ian Cinnamon撰写的"为邪恶的天才编程视频游戏"一书.在其中一个项目中,他解释了如何为赛车游戏创建动画.我在下面编写了一个简单的代码(删除了"几乎 ...

  8. Java代码制作ie浏览器_[Java教程]判断IE浏览器代码实例

    [Java教程]判断IE浏览器代码实例 0 2015-08-12 01:00:19 判断IE浏览器代码实例: 由于当下浏览器类型众多,并且对同一段代码的解读有时候各有不同,所以要根据浏览器的类型来执行 ...

  9. java可以制作动画么_java – 如何为陀螺制作动画?

    物体旋转的轴的旋转称为 Precession.旋转顶部运动需要2次旋转: >物体围绕其内轴旋转(与红色手柄平行). >围绕静态轴旋转其中一个内部轴(在本例中为z). 从表面上看,你需要2个 ...

最新文章

  1. C# 访问并打开局域网文件夹
  2. ubuntu 13.04下MYSQL 5.5环境搭建
  3. 有关session的登录注销的一个小例子
  4. 数据结构之稀疏数组 - SparseArray
  5. wcf高并发 mysql_使用nginx搭建高可用,高并发的wcf集群
  6. 宝岛探险1(DFS)
  7. py-R-FCN安装记录
  8. 手机拍照怎么识别文字
  9. 当刷机工具遇到SetupConnection时的解决方法
  10. 基于深度强化学习的柔性作业车间动态调度
  11. MacOS 单机搭建 Pulsar 集群
  12. 摩尔定律即将走向终结?对未来更广阔世界影响的55个预测!
  13. java ext_ext下载及使用
  14. PUNCH图剖分浅析
  15. 七巧板复原之剩余区域的计算-多边形的加减法计算
  16. mongodb数据文件格式
  17. CELLID GET
  18. 厦大C语言上机 1510 小明的随机数
  19. 使用电信云时做对象储存时的异常信息:com.amazonaws.services.s3.model.AmazonS3Exception
  20. Linux(deepin) 解决 Anaconda 环境中 matplotlib 中文乱码问题

热门文章

  1. java获取绝对路径_JAVA获取项目绝对路径
  2. 3个月内爆胎鼓包全额赔付 京东轮胎节送“轮胎险”解后顾之忧
  3. 谷歌官方正式发布了Go1.20稳定版「8千字详解」
  4. qtcp多用户同时发信息的信号处理_FPGA进行数字信号处理的相关问题有哪些?来看数字信号处理系统架构分析!...
  5. IdentityServer4(一):概念及基本介绍
  6. 【python自动化】02. pywin32库自动操作键鼠(保姆级代码注释)
  7. 羁绊着项目管理的六大考评缺陷
  8. Java学习之路整理-技术书从入门到进阶最全50+本(珍藏版 )
  9. HTTP请求行、请求头、请求体详解
  10. centos6开启telnet远程登录