-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherData.java
More file actions
45 lines (35 loc) · 1.14 KB
/
WeatherData.java
File metadata and controls
45 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package ObserverPattern.JavaBuiltInExample;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
public class WeatherData {
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private float temperature;
private float humidity;
private float pressure;
public WeatherData() {
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener);
}
public void measurementsChanged() {
pcs.firePropertyChange("measurements", null, this);
}
public void setMeasurements(float temperature, float humidity, float pressure) {
this.temperature = temperature;
this.humidity = humidity;
this.pressure = pressure;
measurementsChanged();
}
public float getTemperature() {
return temperature;
}
public float getHumidity() {
return humidity;
}
public float getPressure() {
return pressure;
}
}