package slider; import java.util.List; import java.util.LinkedList; public class SliderModel { String title = "Title to Be Supplied"; int minValue; int maxValue; int value; // observers is a list of views that want to be notified of changes // to the model List observers = new LinkedList(); public SliderModel (int minV, int maxV, int startV, String label) { minValue = minV; maxValue = maxV; value = startV; title = label; } public int getValue() { return value; } public int getMinValue() { return minValue; } public int getMaxValue() { return maxValue; } public String getTitle() { return title; } public void setValue(int v) { // notify observers that the value has changed and pass them the *old* // value. They can query for the new value at their leisure int old_value = value; value = v; for (SliderView observer: observers) { observer.valueChanged(old_value); } } public void setTitle(String t) { // notify observers that the value has changed and pass them the *old* // value. They can query for the new value at their leisure String old_title = title; title = t; for (SliderView observer: observers) { observer.titleChanged(old_title); } } public void addObserver(SliderView view) { observers.add(view); } }