예제 #1
0
 public void initGame() {
   String cfgname = null;
   if (isApplet()) {
     cfgname = getParameter("configfile");
   } else {
     JFileChooser chooser = new JFileChooser();
     chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
     chooser.setDialogTitle("Choose a config file");
     int returnVal = chooser.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
       cfgname = chooser.getSelectedFile().getAbsolutePath();
     } else {
       System.exit(0);
     }
     // XXX read this as resource!
     // cfgname = "mygeneratedgame.appconfig";
   }
   gamecfg = new AppConfig("Game parameters", this, cfgname);
   gamecfg.loadFromFile();
   gamecfg.defineFields("gp_", "", "", "");
   gamecfg.saveToObject();
   initMotionPars();
   // unpause and copy settingswhen config window is closed
   gamecfg.setListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           start();
           requestGameFocus();
           initMotionPars();
         }
       });
   defineMedia("simplegeneratedgame.tbl");
   setFrameRate(35, 1);
 }
예제 #2
0
 public static void main(String[] pArgs) {
   try {
     AppConfig appConfig = new AppConfig(new File(pArgs[0]));
     System.out.println("version: " + appConfig.getAppVersion());
     System.out.println("appname: " + appConfig.getAppName());
   } catch (Exception e) {
     e.printStackTrace(System.err);
   }
 }
예제 #3
0
 public void doFrameTitle() {
   if (getKey('G')) {
     clearKey('G');
     gamecfg.openGui();
     // pause until window closed
     stop();
   }
 }
예제 #4
0
 /**
  * 单例模式
  *
  * @return
  */
 public static AppConfig getInstance(String configFileName) {
   if (conf == null) {
     conf = new AppConfig();
     try {
       InputStream is =
           Thread.currentThread().getContextClassLoader().getResourceAsStream(configFileName);
       conf.load(is);
       is.close();
     } catch (IOException e) {
       System.err.println(configFileName + "文件读取失败!");
     }
   }
   return conf;
 }
예제 #5
0
  /** 存储到props文件的格式中 */
  public void storeToProps() {
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(configFile);
    } catch (FileNotFoundException e1) {
      System.out.println("文件未找到:" + configFile + e1.toString());
    }

    try {
      conf.store(fos, "");
    } catch (FileNotFoundException e) {
      System.err.println("配置文件" + configFile + "找不到!!\n" + e.toString());
    } catch (Exception e) {
      System.err.println("读取配置文件" + configFile + "错误!!\n" + e.toString());
    }
  }