首页 新闻 会员 周边

ProgressMonitor进度条窗口关闭问题

0
[待解决问题]

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.Timer;






public class ProgressBar implements Runnable {
    static Timer tm;
    ProgressMonitor pm;
    JFrame poi;

    int i;

    public ProgressBar() {
       
    }

    public void run() {
        ActionListener actionListener = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                pm.setProgress(++i == 100 ? 1 : i);
            }
        };
        tm = new Timer(50, actionListener);
        pm = new ProgressMonitor(poi,"","正在发生,请稍后...", 0, 100);
        pm.setMillisToDecideToPopup(0);
        pm.setMillisToPopup(0);
        tm.start();

    }

    public static void main(String[] args) {
        ProgressBar p = new ProgressBar();
        Thread th = new Thread(p);
        try {
            th.start();
        } catch (Exception e) {
            // th.interrupt(); 
        }
    }
   
    public void stop() {
        ProgressBar p = new ProgressBar();
        Thread th = new Thread(p);
        try {
             pm.close();
        return;
        } catch (Exception e) {
           System.out.println(e);
        }
    }
   

}

我想在需要的地方调用stop()方法关闭进度条窗口。     pm.close();没起作用

jeay的主页 jeay | 初学一级 | 园豆:0
提问于:2010-12-02 18:10
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册