进度条

import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JPanel;

public class Jindu {

private JFrame frame;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Jindu window = new Jindu();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public Jindu() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JProgressBar a= new JProgressBar();
a.setStringPainted(true);
JPanel panel = new JPanel();
a.setBackground(Color.GREEN);
panel.setBounds(49, 119, 375, 116);
frame.getContentPane().add(panel);
panel.add(a);
new Thread(){

public void run(){
for (int i = 0; i <= 100; i++) {
try {
Thread.sleep(100); // 让当前线程休眠0.1ms
} catch (InterruptedException e) {
// TODO: handle exception
e.printStackTrace();
} a.setValue(i); // 设置进度条数值

}
a.setString("创建成功");// 设置提示信息
}
}.start();
}
}

posted @ 2017-10-11 18:14  637  阅读(105)  评论(0编辑  收藏  举报