本代码需要配置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();
//图片3
ImageView 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();
//图4
ImageView 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();
//图5
ImageView 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();
//图6
ImageView 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();
//图7
ImageView 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
//图7
ImageView 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();
//图8
ImageView 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();
//图9
ImageView 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();
//图10
ImageView 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();
//11
ImageView 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();
//12
ImageView 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();
//13
ImageView 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();
//14
ImageView 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();