功能说明: 代码实现了多种幻灯片变换特效. 如:淡入淡出、缓慢覆盖、旋转覆盖等10多种变换效果。

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了瓮安免费建站欢迎大家使用!
功能实现:
1、图片加载类ImageLoader实现:
1)用阻塞队列存储要图片:BlockingQueue images = new ArrayBlockingQueue<>(2);
2)用图片eof表示图片队列结束:Image eof = new WritableImage(1, 1);
3)循环读取指定图片,由于是阻塞队列,所以当队列满的时候线程会自动阻塞.
- public void run() {
 - int id = 0;
 - try {
 - while (true) {
 - String path = resources[id];
 - InputStream is = getClass().getResourceAsStream(path);
 - if (is != null) {
 - Image image = new Image(is, width, height, true, true);
 - if (!image.isError()) {
 - images.put(image);
 - }
 - }
 - id++;
 - if (id >= resources.length) {
 - id = 0;
 - }
 - }
 - } catch (Exception e) {
 - } finally {
 - if (!cancelled) {
 - try {
 - images.put(eof);
 - } catch (InterruptedException e) {
 - }
 - }
 - }
 - }
 
2、特效实现 以弧形切换图片为例: 首先定义LengthTransition变化特效:设置变化时间,以及弧度数跟时间的变化关系。
- class LengthTransition extends Transition {
 - Arc arc;
 - public LengthTransition(Duration d, Arc arc) {
 - this.arc = arc;
 - setCycleDuration(d);
 - }
 - @Override
 - protected void interpolate(double d) {
 - arc.setLength(d * 360);
 - }
 - }
 
然后设置图片层叠效果:
- group.setBlendMode(BlendMode.SRC_OVER);
 - next.setBlendMode(BlendMode.SRC_ATOP);
 
以及之前那张图片的淡出特效:
- FadeTransition ft = new FadeTransition(Duration.seconds(0.2), mask2);
 
最后同时执行这两个特效:
- ParallelTransition pt = new ParallelTransition(lt, ft);
 
效果图:
源码下载: 进入下载页面
原文链接:http://www.cnblogs.com/javafx/archive/2013/03/30/2990259.html
Copyright © 2009-2022 www.wtcwzsj.com 青羊区广皓图文设计工作室(个体工商户) 版权所有 蜀ICP备19037934号