public abstract class Event implements Runnable {
public void run() {
try {
Thread.sleep(delayTime);
action();
} catch(Exception e) {e.printStackTrace();}
}
}
I have this event class above, when I try to start the thread it runs the first command of the thread - Thread.sleep(delayTime); Since the Event class is abstract I want to run some of its child class methods. For example, when I call action(); it should run the action method from the below child class
public class ThermostatNight extends Event {
public ThermostatNight(long delayTime) {
super(delayTime);
}
public void action() {
System.out.println(this);
thermostat = "Night";
}
public String toString() {return "Thermostat on night setting";}
}
There are many such child classes, like ThermostatDay, FanOn, FanOff who are very similar as above. What should I do the call action(); after sleep is called from the run() command in Event class ?
Any ideas?
Your help is appreciated!