http://nakkakaya.com/2009/11/08/command-line-progress-bar/“rel=“noestlow”> (Nurullah Akkaya):
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
try {
Thread.sleep(100);
}
catch (Exception e) {
}
printProgBar(i);
}
}
public static void printProgBar(int percent){
StringBuilder bar = new StringBuilder("[");
for(int i = 0; i < 50; i++){
if( i < (percent/2)){
bar.append("=");
}else if( i == (percent/2)){
bar.append(">");
}else{
bar.append(" ");
}
}
bar.append("] " + percent + "% ");
System.out.print("
" + bar.toString());
}
无论出于何种原因,这都是按以下方式得出的:
[> ] 0%
[=====> ] 10%
[==========> ] 20%
[===============> ] 30%
[====================> ] 40%
[=========================> ] 50%
[==============================> ] 60%
[===================================> ] 70%
[========================================> ] 80%
[=============================================> ] 90%
如果我真的希望它按照正常的ole窗更新一条线。
是否有任何途径来效仿这种行为,以便它能够在一个Eclipse窗口中发挥作用?