Code example for Observable

Methods: addObserver

0
	private double humidity;
	Observable weatherData;
	 
	public CurrentConditionsDisplay(Observable weatherData) {
		//this.weatherData = weatherData; 
		weatherData.addObserver(this);
	} 
	 
	public void display() { 
		System.out.println("##################################");
		System.out.println("Current conditions display");
		System.out.println("Temperature " + temperature);
		System.out.println("Pressure " + pressure);
		System.out.println("Humidity " + humidity);
		System.out.println("##################################");
	} 
 
	public void update(Observable o, Object arg) {
		if(o instanceof WeatherData) {
			WeatherData weatherData = (WeatherData) o;
			this.temperature = weatherData.getTemperature();