Observer (5.6)

Design, code and test an applet with two components as follows. Each component represents an integer value in the same range, e.g., a slider in the range 0 to 100 and a textfield that only takes an integer in the same range. Connect the two components so that they always show the same value. When the value of one component is changed by a user action the value of the other component is changed by the program so that the two values remain equal.

The problem can be solved by making the two components aware of each other, but this makes them hardly reusable. Or the problem can be solved using an observer. The observer looks for changes in the value of each component and when the value of one component changes and tells the other component to change value accordingly.