Code example for Observable

Methods: addObserver

0
	private float temperature ;
	private float humidity;
	 
	public CurrentConditionsDisplayUtil(Observable observable){
		this.observable = observable;
		observable.addObserver(this);
	} 
	@Override 
	public void display() { 
		// TODO Auto-generated method stub 
		System.out.println("Current Conditions:"+temperature +"F degrees and " + humidity +"%humidity");
	} 
 
	@Override 
	public void update(Observable obs, Object arg1) {
		// TODO Auto-generated method stub 
		if(obs instanceof WeatherDataUtil){
			WeatherDataUtil weatherDataUtil = (WeatherDataUtil)obs;
			this.temperature = weatherDataUtil.getTemperature();
			this.humidity = weatherDataUtil.getHumidity();
			display();