import javax
import java
/*
JWindow 是一個能夠在用戶桌面的任何地方顯示的容器
所以能夠使用它構成程序剛運行時的splash畫面
*/
public class ESplash extends JWindow implements Runnable {
private Thread thread = null;
private Image logo = null;
private Color bg_color = new Color(
private Toolkit toolkit =getToolkit();
private int image_width;
private int image_height;
public ESplash() {
logo = new ECreateIcon()
loadImage(logo
image_width = logo
image_height = logo
setBackground(bg_color);
setCursor(new Cursor(
setSize(image_width +
//設置JWindow的顯示位置
int Xpos = (toolkit
int Ypos = (toolkit
setBounds(Xpos
setVisible(true);
}
/*
通過使用MediaTracker加載圖像
圖像被加載後
*/
private void loadImage(Image image
if(image != null) {
MediaTracker tracker = new MediaTracker(this);
tracker
try {
tracker
}
catch(InterruptedException _ex) { }
}
}
/*
在JWindow部件上繪制圖像
*/
public void paint(Graphics g) {
g
//設置字體的色彩
g
g
//設置矩形框的背景色彩
g
//繪制矩形框
g
g
//重新設置將要填塗在矩形框中的顏色
g
for(int n =
try {
//線程休眠
Thread
//填塗矩形框
g
}
catch(Exception _ex) { }
}
public void run() {
//設置鼠標為等待狀態
setCursor(new Cursor(
repaint();
}
public void stop() {
//結束線程
thread = null;
logo = null;
}
//更新圖形區
public void update(Graphics g) {
paint(g);
}
}
/////////////////////////////////////////////////////
import java
import java
import java
import javax
public class ECreateIcon{
private static Image splashimage;
public ECreateIcon(){
splashimage = getImageFromResource(
}
//獲得圖像
private Image getImageFromResource(String image_path) {
return Toolkit
}
public ImageIcon createImageIcon(String filename) {
String path =
return new ImageIcon(getClass()
}
public Image getSplashImage() {
return splashimage;
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26698.html