"Thinkinginjava" 20, the use of control framework (initialization of the system use)

Source: Internet
Author: User

/*** 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.