Listing 1.
public class IllusionApplet extends Applet{
private int canvasWidth, canvasHeight;
private RegisterObject ro;
/* Shapes (models or observables) used
in this applet */
private StandardLineShape stdLine;
public void init(){
// this object helps coordinates &
between shapes
ro = new RegisterObject
(lineThicknessInPixels);
/* create models or observables */
stdLine = new
StandardLineShape(canvasWidth, canvasHeight,
ro);
}
Listing 2.
// methods / public / IObservable implementation
public void addIObserver(IObserver anIObserver) {
myObservableComponent.addIObserver(anIObserver);
}
public void deleteIObserver(IObserver anIObserver) {
myObservableComponent.deleteIObserver(anIObserver);
}
public void deleteIObservers() {
myObservableComponent.deleteIObservers();
}
Listing 3.
// IObservable implementation
public void addIObserver(IObserver anIObserver) {
myObservableComponent.addIObserver &
(anIObserver); }
public void deleteIObserver(IObserver anIObserver) {
myObservableComponent.deleteIObserver &
(anIObserver); }
public void deleteIObservers() {
myObservableComponent.deleteIObservers(); }
// IObserver implementation
public void update(Object theObserved, &
Object changeCode){
updateMe();
myObservableComponent.notifyIObservers &
(theObserved,changeCode);
}
©Board of Trustees, University of Illinois,
1997. Information concerning use of these classes and interfaces
can be obtained from the Department of Psychology, University of
Illinois, 603 E. Daniel, Champaign, Illinois 61801. Redistribution and
use, with and without modifications, are permitted for any purpose provided
that the source code retain the above copyright notice. All
publications or advertising materials mentioning features or use
of this software must acknowledge that it was developed by the University
of Illinois at Urbana-Champaign and credit the contributors. THIS SOFTWARE
IS PROVIDED BY THE UNIVERSITY AND THE CONTRIBUTORS “AS IS” WITH NO WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED. In no event shall the University
or the contributors be liable for any damages suffered by the users arising
out of the use of this software, even if advised of the possibility
of such damage.