/Users/lyon/j4p/src/bookExamples/ch19Events/observables/ObserverOfPoint3d.java

1    package bookExamples.ch19Events.observables; 
2     
3    import java.util.Observable; 
4    import java.util.Observer; 
5     
6    public class ObserverOfPoint3d implements Observer { 
7        public void update(Observable observable, 
8                           Object o) { 
9            System.out.println("observable =" + 
10                   observable); 
11           System.out.println(observable.getClass().getName()); 
12           System.out.println("argument=" + 
13                   o); 
14           ObservablePoint3d p3d = (ObservablePoint3d) (observable); 
15           System.out.println("got points! d1,d2,d3=" + 
16                   p3d.getD1() + "," + p3d.getD2() + "," + p3d.getD3()); 
17       } 
18    
19   } 
20    
21    
22   class Mediator { 
23       ObservablePoint3d op3d = new ObservablePoint3d(); 
24       ObserverOfPoint3d observer = new ObserverOfPoint3d(); 
25    
26       public void wire() { 
27           op3d.addObserver(observer); 
28           op3d.setD1(-99); 
29           op3d.notifyObservers(); 
30       } 
31    
32       public static void main(String args[]) { 
33           Mediator m = new Mediator(); 
34           m.wire(); 
35       } 
36   } 
37