public static void showDialog (final Thread thread, String msg) {
final JDialog dialog = new JDialog() ;
dialog.addWindowListener (new WindowAdapter() {
public void windowOpened (WindowEvent e) {
thread.start() ;
new Thread (new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while (true){
if(!thread.isAlive()){
dialog.dispose();
System.out.print("结束计算");
break;
}
}
}
}).start();
}
});
Container conn = dialog. getContentPane() ;
JProgressBar progressBar = new JProgressBar() ;
progressBar.setIndeterminate (true) ;
progressBar.setStringPainted (true) ;
progressBar.setString (msg) ;
conn.add(progressBar) ;
dialog.setTitle("正在操作中...");
dialog.setResizable (false) ;
dialog.setUndecorated (true) ;
dialog.setSize(500,50) ;
dialog.setLocationRelativeTo (null) ;
dialog.setModal (true) ;
dialog.setVisible (true) ;
}
showDialog(new Thread(new Runnable() {
@Override
public void run() {
}
} ), "计算中..........");