每隔一秒,增加10%,100%时,进度条消失
package three.day.frame;
import javax.swing.JProgressBar;import javax.swing.JWindow;
import javax.swing.SwingConstants;
public class JProgressBarDemo01 {
public static void main(String[] args) {
final JProgressBar progbar = new JProgressBar(SwingConstants.HORIZONTAL,0,10);
progbar.setValue(0);
progbar.setStringPainted(true);
final JWindow win = new JWindow();
win.setBounds(300,200,300,26);
win.add(progbar);
win.setVisible(true);
new Thread(new Runnable(){
private int value = 0;
public void run(){
while (true) {
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
++value;
if (value == 10) {
progbar.setValue(value);
win.dispose();
System.exit(0);
}
progbar.setValue(value);
}
}
}).start();
}
}