java

位置:IT落伍者 >> java >> 浏览文章

用java的jwindow运行出的splash画面


发布日期:2022年07月04日
 
用java的jwindow运行出的splash画面

import javaxswing*;

import javaawt*;

/*

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()getSplashImage();

loadImage(logo );

image_width = logogetWidth(this);

image_height = logogetHeight(this);

setBackground(bg_color);

setCursor(new Cursor());

setSize(image_width + image_height + );

//设置JWindow的显示位置

int Xpos = (toolkitgetScreenSize()width getSize()width) / ;

int Ypos = (toolkitgetScreenSize()height getSize()height) / ;

setBounds(Xpos Ypos getSize()width getSize()height);

setVisible(true);

}

/*

通过使用MediaTracker加载图像确保图像被正确的加载

图像被加载后将进行绘图

*/

private void loadImage(Image image int ID) {

if(image != null) {

MediaTracker tracker = new MediaTracker(this);

trackeraddImage(image ID);

try {

trackerwaitForID(ID);

}

catch(InterruptedException _ex) { }

}

}

/*

在JWindow部件上绘制图像

*/

public void paint(Graphics g) {

gdrawImage(logo image_width image_height this);

//设置字体的色彩

gsetColor(new Color( ));

gdrawString(正在初始化系统 getSize()height );

//设置矩形框的背景色彩

gsetColor(new Color( ));

//绘制矩形框

gfillRect( getSize()height );

gdrawRect( getSize()height );

//重新设置将要填涂在矩形框中的颜色

gsetColor(new Color( ));

for(int n = ; n < ; n += )

try {

//线程休眠毫秒

Threadsleep(L);

//填涂矩形框

gfillRect( getSize()height n );

}

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 javaawt*;

import javaawtimage*;

import javaawtevent*;

import javaxswing*;

public class ECreateIcon{

private static Image splashimage;

public ECreateIcon(){

splashimage = getImageFromResource(resources/images/Esplashgif);

}

//获得图像

private Image getImageFromResource(String image_path) {

return ToolkitgetDefaultToolkit()getImage(image_path);

}

public ImageIcon createImageIcon(String filename) {

String path = /resources/images/ + filename;

return new ImageIcon(getClass()getResource(path));

}

public Image getSplashImage() {

return splashimage;

}

}

上一篇:使用Axis2以普通的Java类建立Web Services

下一篇:java的算术运算符