我正在处理启动画面。我设法上了一堂课。下面是一个显示启动画面的类。我的问题是如果我从 JFrame 调用这个类并运行,JFrame 和启动画面会同时运行,并且在启动画面应该持续的持续时间之后它们都关闭。如何让它们同时显示?
谢谢一堆
public class Splash extends JWindow {
AbsoluteLayout abs;
AbsoluteConstraints absImage, absBar;
ImageIcon image;
JLabel label;
JProgressBar bar;
public Splash() {
abs = new AbsoluteLayout();
absImage = new AbsoluteConstraints(0, 0);
absBar = new AbsoluteConstraints(0, 210);
label = new JLabel();
image = new ImageIcon(this.getClass().getResource("anime.gif"));
label.setIcon(image);
bar = new JProgressBar();
bar.setPreferredSize(new Dimension(350,10));
this.getContentPane().setLayout(abs);
this.getContentPane().add(label, absImage);
this.getContentPane().add(bar, absBar);
new Thread() {
public void run() {
for (int i = 0; i < 100; i++) {
bar.setValue(i);
try {
sleep(80);
} catch (InterruptedException ex) {
Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
}
}
System.exit(0);
}
}.start();
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}