| |
| java进度条 |
| |
发布者: 发布时间:2007-01-02 |
|
|
|
|
|
import java.io.IOException;
public class TextProcess {
private static final int terminalLen = 60;
private float percent = 0.0f;
private float oldPercent = percent;
private String desc = "Running:";
private String processTxt = "=";
private int preLen = 0;
private final static byte[] bytes = new byte[] { 92, 124, 47 };
private int bi = 0;
private boolean stop = false;
public static void main(String[] args) throws IOException { TextProcess test = new TextProcess(); test.run(); float per = 0.0f; for (int i = 0; i < 100; i++) { per += 0.01; test.setPercent(per); try { Thread.sleep(200); } catch (InterruptedException e) { } } test.stop(); }
public void stop() { this.stop = true; }
public void run() { Thread run = new Thread() { public void run() { while (!stop) { try { TextProcess.this.print(); Thread.sleep(100); } catch (Exception e) { }
}
} };
run.start(); }
public void print() throws IOException { for (; preLen > 0; preLen--) { System.out.write(8); } System.out.print(this.desc); preLen = this.desc.length(); int processLen = (int) ((terminalLen-preLen) * this.percent); for (int i = 0; i < processLen; i++) { System.out.print(this.processTxt); preLen++; System.out.flush(); } for(int i=terminalLen-preLen;i>0;i--) { System.out.print(' '); preLen++; } System.out.write(bytes[bi]); bi = ++bi % 3; preLen++; String txtPer = String.valueOf(Math.round(this.percent * 100)) + "%"; System.out.print(txtPer); preLen += txtPer.length(); }
public static byte[] getBytes() { return bytes; }
public TextProcess(String desc, String processTxt) { super(); this.desc = desc; this.processTxt = processTxt; }
public TextProcess() { }
public String getDesc() { return desc; }
public void setDesc(String desc) { this.desc = desc; }
public String getProcessTxt() { return processTxt; }
public void setProcessTxt(String processTxt) { this.processTxt = processTxt; }
public float getPercent() { return percent; }
public void setPercent(float percent) { this.percent = percent; }
} | |
|
| (转载文章请保留出处:北天JAVA技术网(www.java114.com)) |
| |
| 更多精彩文章: |
| 商业智能和决策分析 |
| OA办公软件闹革命 阵营开始分化 |
| ERP走向平台化 |
| YODODO苗湾儿:为自己的梦想打工 |
| 数据库综合知识 |
| 保护Access 2000数据库的安全 |
| |
| 最近评论: |
|
|
| 你曾悄悄的来过! |
| wow gold,wow gold,wow gold,ffxi gil max(526) |
|
|
| 冰封的往事! |
| wow power leveling,wow gold,wow power leveling,wow gold
max(3753) |
|
|
| 冰封的往事! |
| wow power leveling,wow gold,WoW Gold,wow gold
max(5488) |
|
|
| 飞舞的传奇! |
| 传世私服,传世私服.传奇世界私服传奇世界私服,传世私服传世私服, 传奇世界私服传奇世界私服.传奇私服传奇私服. max(7047) |
|
|
| |
| 免责声明:该文章由网友发表,如果对您造成侵权,请联系站长。 |
|