//这是主程序的main函数
public static void main(String args[])
{
    splash myLogo = new splash(); //for creting an object
    myLogo.setVisible(true); //show the logo
    frame = new frameApp(); //for running the progam
    myLogo.setVisible(false); //hide the logo
    myLogo = null; // no longer use it
}//这是展示窗口的文件内容
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JWindow;public class splash extends JWindow
{
    splash()
    {
        JPanel panel = new JPanel()
        {
            //for painting the component
            public void paintComponent(Graphics g)
            {
                //for getting the image
                ImageIcon img = new ImageIcon(ClassLoader.getSystemResource ("frameApp/images/Logo.JPG"));
                //for drawing the image
                g.drawImage(img.getImage(), 0, 0, null);
                super.paintComponent(g);
            }
        };
        
        //for setting the border
        panel.setOpaque(false);
        //for setting the panel in the contentPane
        panel.setBorder(BorderFactory.createEtchedBorder());
        panel.setBackground(Color.BLUE);
        //for setting the ContentPane to true
        setContentPane(panel);
        
        setSize(350, 250);
        Dimension frameSize = getSize();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        setVisible(true);
    }
}

解决方案 »

  1.   

    class SplashWindow extends JWindow 
    {
    public SplashWindow(String filename, int waitTime) 
    {
    //super(f);
    JLabel l = new JLabel(new ImageIcon(filename));
    ImageIcon img = new ImageIcon(ClassLoader.getSystemResource ("123.gif"));
    ;
    getContentPane().add(l, BorderLayout.CENTER);
    pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension labelSize = l.getPreferredSize();
    setLocation(
    screenSize.width/2 - (labelSize.width/2),
    screenSize.height/2 - (labelSize.height/2));
    addMouseListener(new MouseAdapter() 
    {
    public void mousePressed(MouseEvent e) 
    {
    setVisible(false);
    dispose();
    Frame_2 fra2=new Frame_2();
    }
    });
    final int pause = waitTime;
    final Runnable closerRunner = new Runnable() 
    {
    public void run() 
    {
    setVisible(false);
    dispose();
    }
    };
    Runnable waitRunner = new Runnable() 
    {
    public void run() 
    {
    try 
    {
    Thread.sleep(pause);
    SwingUtilities.invokeAndWait(closerRunner);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    };
    this.setVisible(true);
    Thread splashThread = new Thread(waitRunner, "SplashThread");
    splashThread.start();
    System.out.println("---------");
    }
    }