-
Notifications
You must be signed in to change notification settings - Fork 0
/
Obs1.java
64 lines (45 loc) · 964 Bytes
/
Obs1.java
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
56
57
58
59
60
61
62
63
64
import java.util.ArrayList;
interface Observable {
public void addObserver(Observer1 o);
public void notifyObservers();
}
interface Observer1 {
public void update(int a);
}
public class Obs1 implements Observable {
public int jeden = 3;
ArrayList lista = new ArrayList();
public static void main(String[] args) {
Obs1 paper = new Obs1();
window1 okno = new window1();
paper.addObserver((Observer1) okno);
paper.zmiana();
paper.jeden=11;
paper.zmiana();
}
public void zmiana() {
this.notifyObservers();
}
@Override
public void addObserver(Observer1 o) {
lista.add(o);
}
@Override
public void notifyObservers() {
for(int i=0;i<lista.size();i++){
Observer1 ob = (Observer1) lista.get(i);
ob.update(this.jeden);
}
}
}
class window1 implements Observer1 {
private int jeden;
@Override
public void update(int a) {
jeden = a;
this.display();
}
public void display() {
System.out.println(jeden);
}
}