/*** book: "Thinking in Java" * Function: Control framework implementation, 1, the complete implementation of the control framework is created by a single class, so that the implementation of the details are encapsulated. The inner class is used to represent the various action* necessary to solve the problem , and 2, the inner class can easily access any member of the perimeter class, so it is possible to avoid this implementation becoming unwieldy. * File: greenhousecontroller.java* time: April 7, 2015 19:14:33* Author: cutter_point*/package Lession10innerclasses;import lession10innerclasses.controller.*;p Ublic class Greenhousecontroller {public static void main (String [] args) { Greenhousecontrols gc = new Greenhousecontrols (); Gc.addevent (Gc.new Bell (900)); Event[] EventList = {gc.new thermostatnight (0), gc.new Lighton (+), gc.new Lightoff (+), gc.new Wateron (+), gc.new Wateroff (+), Gc.new thermostatday (1400)};gc.addevent (gc.new Restart (eventlist)); if (args.length = = 1) { System.out.println ("======================"); Gc.addevent (new Greenhousecontrols.terminate (New Integer (args[0))) ;} System.out.println (System.nanotime ());//system.out.println (Args[0]); Gc.run ();//something that can't be stopped!! }}
All right, this thing is a dead loop!!!
The function in the controller in front of the class run has this thing.
while (Eventlist.size () > 0)
{
For (Event e:new arraylist<event> (eventlist))//Make a copy of EventList to avoid altering the original data
if (E.ready ())
{
System.out.println (e);
E.action ();
Eventlist.remove (e);
}
}
Okay, I can't stop it,!!!!!.
"Thinkinginjava" 20, the use of control framework (initialization of the system use)