幾乎所有時髦的應用都有一個歡迎屏幕
下面是一個最簡單的歡迎屏幕實現
Java代碼
class SplashWindow
{
public SplashWindow
{
super(f);
JLabel l = new JLabel(new ImageIcon(filename));
getContentPane()
pack();
Dimension screenSize =
Toolkit
Dimension labelSize = l
setLocation(screenSize
screenSize
setVisible(true);
screenSize = null;
labelSize = null;
}
}
SplashWindow
如果我們運行上面的程序
class SplashWindow
{
public SplashWindow
{
super(f);
JLabel l = new JLabel(new ImageIcon(filename));
getContentPane()
pack();
Dimension screenSize =
Toolkit
Dimension labelSize = l
setLocation(screenSize
screenSize
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
setVisible(false);
dispose();
}
});
setVisible(true);
}
}
和原先的SplashWindow
現在我們有了一個很不錯的歡迎屏幕
Java代碼
class SplashWindow
{
public SplashWindow
{
super(f);
JLabel l = new JLabel(new ImageIcon(filename));
getContentPane()
pack();
Dimension screenSize =
Toolkit
Dimension labelSize = l
setLocation(screenSize
screenSize
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
setVisible(false);
dispose();
}
});
final int pause = waitTime;
final Runnable closerRunner = new Runnable()
{
public void run()
{
setVisible(false);
dispose();
}
};
Runnable waitRunner = new Runnable()
{
public void run()
{
try
{
Thread
SwingUtilities
}
catch(Exception e)
{
e
// 能夠捕獲InvocationTargetException
// 能夠捕獲InterruptedException
}
}
};
setVisible(true);
Thread splashThread = new Thread(waitRunner
splashThread
}
}
這裡的基本思路是利用一個在一定時間內暫停等待的Thread對象
為了解決這個問題
如果要讓歡迎屏幕總是顯示且用戶不能關閉它
總而言之
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26872.html