java多種幻燈片切換特效(經(jīng)典)
功能實現(xiàn):
1、圖片加載類ImageLoader實現(xiàn):
1)用阻塞隊列存儲要圖片:BlockingQueue images = new ArrayBlockingQueue<>(2);
2)用圖片eof表示圖片隊列結(jié)束:Image eof = new WritableImage(1, 1);
3)循環(huán)讀取指定圖片,由于是阻塞隊列,所以當隊列滿的時候線程會自動阻塞.
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、特效實現(xiàn) 以弧形切換圖片為例: 首先定義LengthTransition變化特效:設(shè)置變化時間,以及弧度數(shù)跟時間的變化關(guān)系。
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);
}
}
然后設(shè)置圖片層疊效果:
group.setBlendMode(BlendMode.SRC_OVER);
next.setBlendMode(BlendMode.SRC_ATOP);
以及之前那張圖片的淡出特效:
FadeTransition ft = new FadeTransition(Duration.seconds(0.2), mask2);
最后同時執(zhí)行這兩個特效:
ParallelTransition pt = new ParallelTransition(lt, ft);
效果圖:

相關(guān)文章
在SpringBoot中使用jwt實現(xiàn)token身份認證的實例代碼
你還不會在SpringBoot中使用jwt實現(xiàn)token身份認證嗎,本文小編就給大家詳細的介紹一下在SpringBoot中使用jwt實現(xiàn)token身份認證的實例代碼,感興趣的同學(xué)可以自己動手試一試2023-09-09
Java 實戰(zhàn)圖書管理系統(tǒng)的實現(xiàn)流程
讀萬卷書不如行萬里路,只學(xué)書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+SSM+jsp+mysql+maven實現(xiàn)一個圖書管理系統(tǒng),大家可以在過程中查缺補漏,提升水平2021-11-11

