forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEraser.java
More file actions
38 lines (32 loc) · 818 Bytes
/
Eraser.java
File metadata and controls
38 lines (32 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package onlyfun.caterpillar;
public class Eraser implements Runnable {
private boolean active;
private String mask;
public Eraser() {
this('*');
}
public Eraser(char maskChar) {
active = true;
mask = "\010" + maskChar;
}
// 停止執行緒時設定為false
public void setActive(boolean active) {
this.active = active;
}
public boolean isActive() {
return active;
}
// 重新定義run()方法
public void run () {
while(isActive()) {
System.out.print(mask);
try {
// 暫停目前的執行緒50毫秒
Thread.currentThread().sleep(50);
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}