package test;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class Tes extends JFrame implements ActionListener {
private JButton jb;
private JProgressBar bar;
public Tes() {
bar=new JProgressBar(0, 100);
bar.setStringPainted(true);
// bar.setString("防撒高速钢");
// bar.setSize(900, 60);
JPanel jp=new JPanel();
jb=new JButton("开始");
jb.addActionListener(this);
jp.add(jb);
jp.add(bar);
add(jp);
pack();
this.setResizable(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new Tes();
}
@Override
public void actionPerformed(ActionEvent e) {
Thread thread=new Thread(new Runnable() {
public void run() {
for(int i=0;i<65;i++){
bar.setValue(i*100/65);
bar.setString("已运行"+i*100/65+"%");
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
bar.setString("完成");
bar.setValue(0);
}
});
thread.start();
}
}