View Javadoc
1   package org.woehlke.computer.kurzweil;
2   
3   import lombok.extern.log4j.Log4j2;
4   import org.woehlke.computer.kurzweil.application.ComputerKurzweilFrame;
5   import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
6   import org.woehlke.computer.kurzweil.application.ComputerKurzweilContext;
7   import org.woehlke.computer.kurzweil.commons.Startable;
8   
9   import java.io.File;
10  import java.net.URL;
11  import java.net.URLClassLoader;
12  
13  
14  /**
15   * Class with main Method for Starting the Desktop Application.
16   *
17   * @author Thomas Woehlke
18   * <p>
19   * http://thomas-woehlke.de/p/simulated-evolution/
20   * @see ComputerKurzweilFrame
21   * @see ComputerKurzweilProperties
22   * @see ComputerKurzweilContext
23   * <p>
24   * Simulated Evolution. Artificial Life Simulation of Bacteria Motion depending on DNA.
25   * <p>
26   * Green food appears in a world with red moving cells.
27   * These cells eat the food if it is on their position.
28   * Movement of the cells depends on random and their DNA.
29   * A fit cell moves around and eats enough to reproduce.
30   * Reproduction is done by splitting the cell and randomly changing the DNA of the two new Cells.
31   * If a cell doesn't eat enough, it will first stand still and after a while it dies.
32   * <p>
33   * &copy; 2006 - 2008 Thomas Woehlke.
34   */
35  @Log4j2
36  public class ComputerKurzweilApplication implements Startable {
37  
38      private final ComputerKurzweilFrame frame;
39  
40      public ComputerKurzweilApplication(String[] args) {
41          log.info("start");
42          System.out.println("start");
43          for(String arg:args){
44              log.info(arg);
45              System.out.println(arg);
46          }
47          String configFileName = "/application.yml";
48          URL fileUrl = getClass().getResource(configFileName);
49          File configFile = new File(fileUrl.getFile());
50          log.info("get properties");
51          System.out.println("get properties");
52          ComputerKurzweilProperties properties = ComputerKurzweilProperties.propertiesFactory(configFile);
53          log.info("get Frame");
54          System.out.println("get Frame");
55          this.frame = new ComputerKurzweilFrame(properties);
56          log.info("started");
57          System.out.println("started");
58      }
59  
60      public void start(){
61          try {
62              this.frame.start();
63              log.info("Started the Desktop Application");
64              System.out.println("Started the Desktop Application");
65          } catch (IllegalThreadStateException e){
66              System.out.println(e.getLocalizedMessage());
67              log.info(e.getLocalizedMessage());
68          }
69      }
70  
71      @Override
72      public void stop() {
73          try {
74              this.frame.stop();
75              log.info("Stopped the Desktop Application");
76              System.out.println("Stopped the Desktop Application");
77          } catch (IllegalThreadStateException e){
78              System.out.println(e.getLocalizedMessage());
79              log.info(e.getLocalizedMessage());
80          }
81      }
82  
83      /**
84       * Starting the Desktop Application.
85       *
86       * @param args CLI Parameter.
87       */
88      public static void main(String[] args) {
89          String configFileName = "application.yml";
90          String jarFilePath = "target/computer-kurzweil-app.jar";
91          //ComputerKurzweilApplication application = new ComputerKurzweilApplication(configFileName,jarFilePath);
92          //ComputerKurzweilApplication application = new ComputerKurzweilApplication(configFileName);
93          ComputerKurzweilApplicationion.html#ComputerKurzweilApplication">ComputerKurzweilApplication application = new ComputerKurzweilApplication(args);
94          application.start();
95      }
96  
97  }