2011-11-08 113 views
0

我在一个文件夹中有几个大的数据库文件,我用JAVA处理它们一段时间后,如何使用JProgressbar显示剩余时间百分比?用jprogressbar显示剩余时间?

public int countTrueAmr(String text, String under,String value, String search) { 
     int sLen = under.length(); 
     int count = 0; 
     int index = text.indexOf(under + value, 0); 
     int nextIndex = text.indexOf(under, index + sLen); 
     while (index > 0 && nextIndex > 0) { 
      count += countString(text.substring(index, nextIndex), search); 

      index = text.indexOf(under + value, index + sLen); 
      nextIndex = text.indexOf(under, index + sLen); 
      if (nextIndex < 0) 
       nextIndex = text.length(); 
     } 
     return count; 
    } 

非常感谢......

回答

1
  1. 扩展SwingWorker
  2. 覆盖doInBackground()。把循环放在里面。偶尔调用方法publish(...)
  3. 覆盖process(...)。致电JProgressBarsetValue(i)
+0

可否请给我一个例子?谢谢 – Freeman

+0

请参阅教程:http://download.oracle.com/javase/tutorial/uiswing/components/progress.html – wannik

+0

感谢您的帮助...... :) – Freeman

1

你能举个例子吗?

SwingWorkersetProgress()方法应该是使用,以至于GUI是“事件调度线程上异步通知。”有一个例子hereAPI