import java.awt.*;//引入相应库类
import javax.swing.*;
public class L10_1 extends JWindow {
//进度条组件,因为在线程类L10_01要引用它,所以需要定义为类成员变量
JProgressBar bar = new JProgressBar(1, 100);
//构造函数
public L10_1() {
//背景图片,注意图片的位置
JLabel bsckLmg = new JLabel(new ImageIcon("#"));
bar.setStringPainted(true);
bar.setString("系统正在初始化...");
add(bar, "South");
toFront();// 界面最前
setSize(600, 400);
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((size.width - this.getWidth()) / 2,(size.height - this.getHeight()) / 2);
add(bsckLmg);
this.setVisible(true);//设置进度条显示文本
LX10_1f_FlashThread ft = new LX10_1f_FlashThread(this);
ft.start();
}
public class LX10_1f_FlashThread extends Thread {
private L10_1 fw;
public LX10_1f_FlashThread(L10_1 fw) {
this.fw = fw;
this.setName("LX10_1");
}
public void run(){
System.out.println("当前线程是:"+LX10_1f_FlashThread.currentThread().getName());
while(fw.bar.getValue()<100){
fw.bar.setValue(fw.bar.getValue()+1);
fw.bar.setString("系统正在初始化("+(fw.bar.getValue()+1)+"%)...");
try{
Thread.sleep(200);//当前线程休眠0.2秒
}catch(InterruptedException e){
e.printStackTrace();
}
}
fw.dispose();//关闭窗体
}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
//当前线程名称
new L10_1();
}
}
运行结果如下: