图像Java帮助。不规则间隔的幻灯片放映
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class slide extends JFrame
{
ImageIcon[] iconArray = new ImageIcon[25];
int iconIndex = 0;
JLabel label;
JPanel panel;
slide ()
{
panel = new JPanel();
label = new JLabel();
add(panel);
setTitle("Slide Show");
panel.add(label);
for(int i = 0; i < iconArray.length; i++)
{
iconArray[i] = new ImageIcon("C:/SlideShow/slide0.jpg");
}
Timer timer = new Timer(1000, new TimerListener());
timer.start();
}
private class TimerListener implements ActionListener
{
public void actionPerformed(ActionEvent actionEvent)
{
label.setIcon(iconArray[iconIndex]);
iconIndex++ ;
if(iconIndex == 25)
iconIndex = 0;
}
}
public static void main(String[] args)
{
slide frame = new slide();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
}
}
您知道如何制作幻灯片以显示不同颜色的图片吗>&燃气轮机;时间间隔?例如,第一张图片为1秒,>&燃气轮机;下一个,第三个等3秒>&燃气轮机&燃气轮机&燃气轮机;非常感谢你的帮助
# 1 楼答案
摆动计时器最多有两个延迟。您可以设置初始延迟和间隔延迟
线程可以让您更好地控制图像之间的睡眠时间
下面是一种开发幻灯片放映查看器的方法,它允许您为每个图像设置延迟。我使用了3张来自互联网的图像来测试查看器