这是我为另一个项目准备的课程。它更接近您正在寻找的内容:
public class Splash extends JWindow implements Runnable
{
private static final long serialVersionUID = -3945334716967506918L;
public void run()
{
showSplash(10000);
}
private void showSplash(int duration)
{
JPanel content = (JPanel)getContentPane();
//Set the windows bounds, centering the window
int width = 558;
int height = 430;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);
//build the splash screen
//SPECIAL NOTE: WHEN ADDING A NEW IMAGE TO THE PROJECT, REFRESH ECLIPSE
//WITH F5 SO THAT THE FILE GETS RECOGNIZED. OTHERWISE YOU'LL GET NULLPOINTEREXCEPTION.
JLabel label = new JLabel (new ImageIcon(getClass().getResource("data/images/World_Magnifier_Splash.jpg")));
JLabel copyrt = new JLabel("Copyright 2012, Tactical Enterprises Ltd.", JLabel.CENTER);
copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
content.add(label, BorderLayout.CENTER);
content.add(copyrt, BorderLayout.SOUTH);
content.setBorder(BorderFactory.createLineBorder(Color.BLACK, 5));
//display
setVisible(true);
try
{
Thread.sleep(duration);
}
catch(Exception e){}
setVisible(false);
}
}
您可以通过创建一个线程在 main 方法中运行它,如下所示:
Thread t = new Thread(new Splash());
t.start();
希望这可以帮助。