-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeepThread.java
More file actions
55 lines (50 loc) · 1.25 KB
/
BeepThread.java
File metadata and controls
55 lines (50 loc) · 1.25 KB
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
48
49
50
51
52
53
54
55
package MultiThread;
import java.awt.*;
public class BeepThread extends Thread{
int count;
int gap;
Toolkit tool = Toolkit.getDefaultToolkit();
BeepThread(int count, int gap){
this.count = count;
this.gap = gap;
}
public void run(){
for(int num=0; num < count; num++){
tool.beep();
try{
Thread.sleep(gap);
} catch(InterruptedException e) {}
}
}
}
class PrintThread3 extends Thread{
char ch;
PrintThread3(char ch){
super();
this.ch = ch;
}
public void run(){
for(int num=0; num<30; num++){
System.out.print(ch);
try{
Thread.sleep(100);
} catch(InterruptedException e) {}
}
}
}
class JavaTest3{
public static void main(String[] args){
PrintThread3 worker1 = new PrintThread3('X');
worker1.start();
PrintThread3 worker2 = new PrintThread3('.');
worker2.start();
BeepThread beep = new BeepThread(5, 1000);
beep.start();
for(int num=0; num<30; num++){
System.out.print("0");
try{
Thread.sleep(100);
} catch (InterruptedException e) {}
}
}
}