import java.util.Observer;
import java.util.Observable;

public class Observ implements Observer {
	ObInt o;

	private Observ() {
		try {
			o = new ObInt();
			o.addObserver(this);
			System.out.println("There are now " + o.countObservers() + " observers");
			Thread.sleep(1000);
			System.out.print("setting value ... ");
			o.setInt(15);
			System.out.println("done");
			Thread.sleep(100);
			Thread.sleep(100);
			Thread.sleep(1000);
		} catch(Exception e) {
			System.out.println(e);
		};
	}

	public static void main(String args[]){
		new Observ();
	}

	public void update(Observable pO, Object pArg){
		System.out.println("Value (id=" + (String)pArg +
			") is now " + ((ObInt)pO).getInt());
	}
}

class ObInt extends Observable {
	private int m_Var;
	public void setInt(int pVar){
		m_Var = pVar;
		System.out.println("observable has changed, notifying observers ...");
		setChanged();
		notifyObservers("ObInt");
	}

	public int getInt(){
		return m_Var;
	}
}

