package threadAndRunnable; import java.awt.BorderLayout; import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar; public class jindutiao extends JFrame { // JProgressBar的使用
private static JProgressBar progress; public jindutiao() {
setTitle("进度条的使用");
setBounds(100, 100, 300, 78);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
progress = new JProgressBar();
// 显示进度文本
progress.setStringPainted(true);
getContentPane().add(progress, BorderLayout.CENTER);
final JLabel jl = new JLabel("产品正在升级...");
getContentPane().add(jl, BorderLayout.NORTH);
setVisible(true);
} public static void main(String[] args) {
new jindutiao();
// 设置进度条为不确定样式
progress.setIndeterminate(true);
for (int i = 0; i < 100; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
progress.setValue(i);
}
progress.setIndeterminate(false);
progress.setString("升级完成!");
}
}