コード例 #1
0
ファイル: BasicBody.java プロジェクト: Ooya/Robot-Sapiens
 /**
  * Creates the brain and launches if it is an agent. The brain class is given as a String. The
  * name argument is used to instantiate the name of the corresponding agent. If the gui flag is
  * true, a bean is created and associated to this agent.
  */
 public void makeBrain(String className, String name, boolean gui, String behaviorFileName) {
   try {
     Class c;
     c = Utils.loadClass(className);
     myBrain = (Brain) c.newInstance();
     myBrain.setBody(this);
     if (myBrain instanceof AbstractAgent) {
       String n = name;
       if (n == null) {
         n = getLabel();
       }
       if (n == null) {
         n = getID();
       }
       if (behaviorFileName != null) setBehaviorFileName(behaviorFileName);
       myBrain.init();
       getStructure().getAgent().doLaunchAgent((AbstractAgent) myBrain, n, gui);
     }
   } catch (ClassNotFoundException ev) {
     System.err.println("Class not found :" + className + " " + ev);
     ev.printStackTrace();
   } catch (InstantiationException e) {
     System.err.println("Can't instanciate ! " + className + " " + e);
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     System.err.println("illegal access! " + className + " " + e);
     e.printStackTrace();
   }
 }