/*
* ProgressSample2.java
*
* Created on 2009年10月11日, 上午10:48
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package Dialog;
/**
*
* @author sony
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
final class Progress extends Thread{
JProgressBar bar=null;
public Progress(JProgressBar bar){
this.bar=bar;
}
public void run() {
bar.setIndeterminate(true);
}
}
public class ProgressSample2 {
public static void main(String[] args){
final JProgressBar bar = new JProgressBar(0, 100);
final JFrame theFrame = new JFrame("Indeterminate");
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton bt=new JButton("ok");
Container contentPane = theFrame.getContentPane();
contentPane.add(bt, BorderLayout.SOUTH);
contentPane.add(bar, BorderLayout.NORTH);
theFrame.setSize(300, 100);
theFrame.show();
bt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new Thread(){
public void run(){
Progress p=new Progress(bar);
p.start();
Thread t=new Thread(){
public void run(){
int i=0;
while(i<10){
System.out.println(i);
i++;
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
};
t.start();
try {
t.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Thread tt=new Thread(){
public void run(){
int i=10;
while(i<20){
System.out.println(i);
i++;
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
};
tt.start();
try {
tt.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
theFrame.dispose();
try {
p.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}.start();
}
});
}
}