十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
功能说明 代码实现了多种幻灯片变换特效 如 淡入淡出 缓慢覆盖 旋转覆盖等 多种变换效果
高邮ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!
功能实现
图片加载类ImageLoader实现
)用阻塞队列存储要图片 BlockingQueue images = new ArrayBlockingQueue( )
)用图片eof表示图片队列结束 Image eof = new WritableImage( )
)循环读取指定图片 由于是阻塞队列 所以当队列满的时候线程会自动阻塞
public void run() {
int id = ;
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 = ;
}
}
} catch (Exception e) {
} finally {
if (!cancelled) {
try {
images put(eof)
} catch (InterruptedException e) {
}
}
}
}
特效实现 以弧形切换图片为例 首先定义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 * )
}
}
然后设置图片层叠效果
group setBlendMode(BlendMode SRC_OVER)
next setBlendMode(BlendMode SRC_ATOP)
以及之前那张图片的吵隐淡出特效
FadeTransition ft = new FadeTransition(Duration seconds( ) mask )
最后同时执行这两个特效渣链
ParallelTransition pt = new ParallelTransition(lt ft)
效果图
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test{
private JFrame frame;
private String scrolledText;
private String str ="滚动文字 Demo";
public static void main(String args[]) {
try{
Test window = new Test();
window.frame.setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}
}
public Test(){
initialize();
}
private void initialize(){
frame.setBounds(100, 100, 500, 375);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setLayout(new BorderLayout());
frame.getContentPane().add(panel, BorderLayout.NORTH);
final JLabel label = new JLabel();
label.setText("New JLabel");
panel.add(label);
label_scrolledText(label);
frame.addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent arg0){
label_scrolledText(label);
}
});
}
public void label_scrolledText(JLabel label) {
this.scrolledText = this.str;
label.setText(scrolledText);
FontMetrics metrics = label.getFontMetrics(label.getFont());
int textW = metrics.stringWidth(label.getText());
Dimension frameSize = frame.getSize();
for (int i = 1; i = (frameSize.width - textW) / 3 - 3; i++)
scrolledText += " ";
label.setText(scrolledText);
Thread thread = new Thread(new TextChanger(label));
thread.start();
}
}
java.lang.NullPointerException
at Test.initialize(Test.java:26)
at Test.init(Test.java:23)
at Test.main(Test.java:16)
package love;import java.applet.Applet;import java.awt.Color;import java.awt.Graphics;import java点虐 .URL;import java.util.Random;/*** 烟花* @author enjoy**/@SuppressWarnings("serial")public class Q extends Applet implements Runnable {public int speed, variability, Max_Number, Max_Energy, Max_Patch,Max_Length, G;public String sound;private int width, height; private Thread thread = null; private BeaClassDemo bcd[]; public void init() { int i;this.setSize(1900, 900); 腊老 width = getSize().width - 1;height = getSize().height - 1;speed = 1; 芦局毁 // 烟花绽放的速度variability = 10;Max_Number = 980; // 可发出烟陪备花的最大数目Max_Energy = width + 50;Max_Patch = 90; // 最大的斑点数Max_Length = 90; // 斑点的最大距离G = 150; // 向地面弯曲的力度bcd = new BeaClassDemo[Max_Number]; for (i = 0; i Max_Number; i++)bcd[i] = new BeaClassDemo(width, height, G); }public void start() { if (thread == null) {thread = new Thread(this);thread.start();}}@SuppressWarnings("deprecation")public void stop() { if (thread != null) {thread.stop();thread = null;}}@SuppressWarnings({ "unused", "static-access" })public void run() {int i;int E = (int) (Math.random() * Max_Energy * 3 / 4) + Max_Energy / 4 + 1;int P = (int) (Math.random() * Max_Patch * 3 / 4) // 烟花的斑点数+ Max_Patch / 4 + 1;int L = (int) (Math.random() * Max_Length * 3 / 4) // 烟花可发射出的距离+ Max_Length / 4 + 1;long S = (long) (Math.random() * 10000); boolean sleep; Graphics g = getGraphics();URL u = null;while (true) {try {thread.sleep(1000 / speed);} catch (InterruptedException x) {}sleep = true;for (i = 0; i Max_Number; i++)sleep = sleep bcd[i].sleep;if (sleep Math.random() * 100 variability) {E = (int) (Math.random() * Max_Energy * 3 / 4) + Max_Energy / 4+ 1;P = (int) (Math.random() * Max_Patch * 3 / 4) + Max_Patch / 4+ 1;L = (int) (Math.random() * Max_Length * 3 / 4) + Max_Length / 4+ 1;S = (long) (Math.random() * 10000);}for (i = 0; i Max_Number; i++) {if (bcd[i].sleep Math.random() * Max_Number * L 1) {bcd[i].init(E, P, L, S);bcd[i].start();}bcd[i].show(g);}}}public void paint(Graphics g) { g.setColor(Color.black); g.fillRect(0, 0, width + 1, height + 1); }}class BeaClassDemo {public boolean sleep = true;private int energy, patch, length, width, height, G, Xx, Xy, Ex[], Ey[], x,y, Red, Blue, Green, t;private Random random; public BeaClassDemo(int a, int b, int g) { width = a;height = b;G = g;}public void init(int e, int p, int l, long seed) {int i;energy = e;patch = p;length = l;// 创建一个带种子的随机数生成器random = new Random(seed);Ex = new int[patch]; Ey = new int[patch]; Red = (int) (random.nextDouble() * 128) + 128;Blue = (int) (random.nextDouble() * 128) + 128;Green = (int) (random.nextDouble() * 128) + 128;Xx = (int) (Math.random() * width / 2) + width / 4;Xy = (int) (Math.random() * height / 2) + height / 4;for (i = 0; i patch; i++) {Ex[i] = (int) (Math.random() * energy) - energy / 2;Ey[i] = (int) (Math.random() * energy * 7 / 8) - energy / 8;
回答于 2023-02-22
向TA提问
官方服务
官方网站
官方网站