-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreader.java
More file actions
executable file
·47 lines (35 loc) · 858 Bytes
/
Threader.java
File metadata and controls
executable file
·47 lines (35 loc) · 858 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
39
40
41
42
43
44
45
46
47
import javax.swing.JTextArea;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
public class Threader implements Runnable {
volatile boolean stop = false;
JTextArea area;
BufferedReader in;
BufferedReader err;
public Threader(JTextArea area, BufferedReader in, BufferedReader err) {
this.area = area;
this.in = in;
this.err = err;
}
public void run() {
while(!stop) {
try {
String s = in.readLine();
if(s != null) {
area.append(s + "\n");
}
String se = err.readLine();
if(se != null) {
area.append(se + "\n");
}
Thread.sleep(1);
} catch(IOException e) {
} catch(InterruptedException e) {
}
}
}
public void stopThreader() {
stop = true;
}
}