forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyApp.java
More file actions
32 lines (25 loc) · 769 Bytes
/
Copy pathMyApp.java
File metadata and controls
32 lines (25 loc) · 769 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
package patterns;
import java.util.Observable;
import java.util.Observer;
import java.util.Scanner;
public class MyApp {
public static void main(String[] args) {
System.out.println("Enter Text: ");
EventSource eventSource = new EventSource();
eventSource.addObserver(new Observer() {
public void update(Observable obj, Object arg) {
System.out.println("Received response: " + arg);
}
});
new Thread(eventSource).start();
}
}
class EventSource extends Observable implements Runnable {
public void run() {
while (true) {
String response = new Scanner(System.in).next();
setChanged();
notifyObservers(response);
}
}
}