import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.Timer;
public class GenTest implements Runnable
{
Timer tm;
ProgressMonitor pm;
JFrame poi;
int i;
public GenTest()
{
// this.poi=poi;
}
public void run()
{
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
pm.setProgress(++i == 100 ? 1 : i);
}
};
tm = new Timer(200, actionListener);
pm = new ProgressMonitor(poi, "", "正在导入,请稍候...", 1, 100);
pm.setMillisToDecideToPopup(0);
pm.setMillisToPopup(0);
tm.start();
}
public static void main(String[] args)
{
GenTest p = new GenTest();
Thread th = new Thread(p);
try
{
th.start();
// 一段需要很长时间的代码
// th.interrupt();
}
catch (Exception e)
{
// th.interrupt();
}
}
}
[转]java 进度条
最新推荐文章于 2023-06-21 17:52:11 发布