JustinKSU 涵盖了问题的技术部分。
更好的策略是image
param
在小程序出现之前使用 来显示“飞溅”。有关详细信息,请参阅小程序的特殊属性。
我想要一个固定的时间......不仅仅是加载。
在这种情况下,将 aCardLayout
放入小程序中。将“splash”添加到第一张卡,GUI 的其余部分添加到另一张卡。在init()
创建一个非重复的 Swing结束时Timer
,它将翻转到带有主 GUI 的卡片。
例如
// <applet code='SplashApplet' width='400' height='400'></applet>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SplashApplet extends JApplet {
public void init() {
final CardLayout cardLayout = new CardLayout();
final JPanel gui = new JPanel(cardLayout);
JPanel splash = new JPanel();
splash.setBackground(Color.RED);
gui.add(splash, "splash");
JPanel mainGui = new JPanel();
mainGui.setBackground(Color.GREEN);
gui.add(mainGui, "main");
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
cardLayout.show(gui, "main");
}
};
Timer timer = new Timer(3000, listener);
// only needs to be done once
timer.setRepeats(false);
setContentPane(gui);
validate();
timer.start();
}
}