package com.ht.bigdata.Progress_bar;
import java.awt.Color;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
public class Demo extends JWindow implements Runnable {
// 定义加载窗口大小
public static final int LOAD_WIDTH = 200;
public static final int LOAD_HEIGHT = 40;
// 获取屏幕窗口大小
public static final int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
public static final int HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
// 定义进度条组件
public JProgressBar progressbar;
// 定义标签组件
public JLabel label;
// 构造函数
public Demo() {
// 创建标签
label = new JLabel("数据加载中,请稍后!!!!");
label.setBounds(0, 0,LOAD_WIDTH , LOAD_HEIGHT - 15);
// 创建进度条
progressbar = new JProgressBar();
// 显示当前进度值信息
progressbar.setStringPainted(true);
// 设置进度条边框不显示
progressbar.setBorderPainted(true);
// 设置进度条的前景色
progressbar.setForeground(new Color(0, 200, 30));
// 设置进度条的背景色
progressbar.setBackground(new Color(168, 200, 198));
progressbar.setBounds(0, LOAD_HEIGHT - 15, LOAD_WIDTH, 15);
// 添加组件
this.add(label);
this.add(progressbar);
// 设置布局为空
this.setLayout(null);
// 设置窗口初始位置
this.setLocation((WIDTH - LOAD_WIDTH) / 2, (HEIGHT - LOAD_HEIGHT) / 2);
// 设置窗口大小
this.setSize(LOAD_WIDTH, LOAD_HEIGHT);
// 设置窗口显示
this.setVisible(true);
}
public static void main(String[] args) {
Demo t = new Demo();
new Thread(t).start();
}
public void run() {
for (int i = 0; i < 100; i++) {
try { Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressbar.setValue(i);
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
JOptionPane.showMessageDialog(this, "加载完成!!!");
this.dispose();
}
}