Implement a 1000ms clock thread
Using the Observer/Observable classes create a number of listener objects that output the clock tick value each time the clock thread ticks
Interface [login to view URL] has one method -- update
Listener objects which implement Observer put their application logic in the update method body
Class [login to view URL] serves as a base class to objects which emit periodic events to Observers.
Invoke methods addObserver, and notifyObsevers in the base class to use the functionality
Beware the ‘hasChanged()’ side-effect of notifyObservers!
Question: How many threads are running in this exercise? Which objects run on which threads?
## Deliverables
Use the following code as a starting point.
import java.util.*;
class Main
{
public static void main (String[] args){
Clock clock;
int clockCycle, limit;
if ([login to view URL] != 2) {
[login to view URL]("usage: clockCycle limit");
[login to view URL](" clockCycle is the length, in milliseconds, of each clock tick");
[login to view URL](" limit is the number of clock ticks until all threads exit");
[login to view URL](" good values are 1000 for clockcycle, 10 for limit");
[login to view URL](-1);
}
clockCycle = new Integer(args[0]).intValue();
limit = new Integer(args[1]).intValue();
/* Create a new Clock object and a number of ClockWatchers
to watch it. Start the clock's thread.
*/
}
}
class Clock ???
{
}
class ClockWatcher ????
{
]
## Platform
Windows