线程--初始化效果

来源:互联网 发布:照片制作软件 编辑:程序博客网 时间:2024/05/21 08:39

代码:

package ls;
import java.awt.*;
import javax.swing.*;

public class c10_1_Flashwind extends JWindow {

JProgressBar bar = new JProgressBar(1, 100);public c10_1_Flashwind() {    JLabel bsckImg = new JLabel(new ImageIcon("2.jpeg"));    bar.setStringPainted(true);    bar.setString("系统正在进行数据初始化...");    this.add(bar, "Center");    this.add(bar, "South");    this.toFront();    this.setSize(600, 400);    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();    this.setLocation((dim.width - this.getWidth()) / 2,(dim.height - this.getHeight()) / 2);    add(bsckImg);    this.setVisible(true);    c10_1f_FlashThread ft = new c10_1f_FlashThread(this);    ft.start();}public class c10_1f_FlashThread extends Thread {    private c10_1_Flashwind fw;    public c10_1f_FlashThread(c10_1_Flashwind fw) {        this.fw = fw;        this.setName("c10_1_Flashwind");    }    public void run(){        System.out.println("当前线程是:"+c10_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(100);            }catch(InterruptedException e){                e.printStackTrace();            }        }        fw.dispose();    }}public static void main(String[] args) {    new c10_1_Flashwind();}}

运行:

这里写图片描述

这里写图片描述

原创粉丝点击