您的位置:首页 > 理论基础 > 数据结构算法

C#中使用Dictionary实现Map数据结构――VC编程网

2014-01-02 20:24 387 查看
这样一段代码,希望能够在执行的时候,显示一个进度条。但是每次进度条都要等到执行完了才显示出来,为什么呢?
Progress p=new Progress(poi);
Thread th=new Thread(p);
try{
th.start();
//一段需要很长时间的代码
//th.interrupt();
}catch(Exception e){
//th.interrupt();
}


package com.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.Timer;

public class Progress implements Runnable {
Timer tm;
ProgressMonitor pm;
JFrame poi;
int i;
public Progress(JFrame poi){
this.poi=poi;
}
public void run() {
ActionListener actionListener=new ActionListener(){
public void actionPerformed(ActionEvent e){
pm.setProgress(++i==100?1:i);
}
};
System.out.println(123);
tm=new Timer(200,actionListener);
pm=new ProgressMonitor(poi,"","正在导入,请稍候...",1,100);
pm.setMillisToDecideToPopup(0);
pm.setMillisToPopup(0);
tm.start();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: