예제 #1
0
 public void drawMenu() {
   try {
     if (page == 3) {
       setFont(16);
       g.drawString(nickname, disWidth + 80, disHeight + 15, 0);
     }
     // 判斷在遊戲說明時,防止文字超出螢幕,當超出螢幕時放到下一頁面
     if (page == 1) {
       setFont(0);
       g.setColor(255, 255, 255);
       for (int i = 0; gameUserInfCount < gameUserInf.length; gameUserInfCount++, i += 17) {
         if (gameUserInfCount % 5 != 4) // 遊戲說明
         g.drawString(gameUserInf[gameUserInfCount], disWidth + 10, disHeight + 70 + i, 0);
         else { // 顯示還有下一頁的文字
           g.drawString(gameUserInf[gameUserInfCount], disWidth + 135, disHeight + 70 + i, 0);
           gameUserInfCount++;
           break;
         }
       }
       flushGraphics();
     }
     changeMeun();
     flushGraphics();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public void commandAction(Command c, Displayable d) {
    if (c == cmdCancel) {
      destroyView();
    }
    // if (c==cmdBookmarks) { new Bookmarks(display, null); }
    if (c == cmdJoin || c == cmdAdd) {
      String nick = nickField.getString().trim();
      String host = hostField.getString().trim();
      String room = roomField.getString().trim();
      String pass = passField.getString();
      int msgLimit = msgLimitField.getValue();

      if (nick.length() == 0) return;
      if (room.length() == 0) return;
      if (host.length() == 0) return;
      StringBuffer gchat = new StringBuffer(room.trim());
      gchat.append('@');
      gchat.append(host.trim());
      // sd.roster.mucContact(gchat.toString(), Contact.ORIGIN_GROUPCHAT);
      if (c == cmdAdd) new Bookmarks(display, new BookmarkItem(gchat.toString(), nick, pass));
      else {
        try {
          gchat.append('/');
          gchat.append(nick);
          join(gchat.toString(), pass, msgLimit);

          display.setCurrent(sd.roster);
        } catch (Exception e) {
          e.printStackTrace();
          // display.setCurrent(new Alert("Exception", e.toString(), null, AlertType.ERROR),
          // sd.roster);
        }
      }
    }
  }
예제 #3
0
  public void showAllRecordForm() {
    fmAllRecords = new Form("All records");
    try {
      RecordEnumeration recEnum = rs.enumerateRecords(null, null, false);
      while (recEnum.hasNextElement()) {
        try {
          // System.out.println(new String(recEnum.nextRecord()));
          String name = "Nenacetl jsem";
          int number = 0;
          try {
            byte[] record = recEnum.nextRecord();
            ByteArrayInputStream buffer = new ByteArrayInputStream(record);
            DataInputStream dis = new DataInputStream(buffer);
            name = dis.readUTF();
            number = dis.readInt();
            dis.close();
          } catch (Exception e) {
          }

          fmAllRecords.append(name + " " + String.valueOf(number) + "\n");
        } catch (Exception e) {
          System.out.println(e.getMessage());
        }

        //
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
    fmAllRecords.addCommand(cmdMenu);
    fmAllRecords.setCommandListener(this);
    dsp.setCurrent(fmAllRecords);
  }
예제 #4
0
  public void run() {
    try {
      if (init) {
        Thread.sleep(500);
        disWidth = (getWidth() - 176) / 2; // 抓取螢幕的中心點
        disHeight = (getHeight() - 208) / 2; // 抓取螢幕的中心點
        drawDisplay();

        systemShowInf("建立資料庫...");
        new DataBaseWrite();
        systemShowInf("設定音樂...");
        GameMain.music = new BackupMusic();
        music = GameMain.music;
        systemShowInf("設定遊戲環境...");
        GameMain.roleData = new RoleDataValue();
        roleData = GameMain.roleData;
        GameMain.gaminf = new GameInfString();
        GameMain.music.musicStart("1");
        spInterface.setFrame(1);
        drawDisplay();
        changeMeun();
        init = false;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #5
0
  public PlanetMap(String s, ChildForm parent, GameProxy gameProxy) {
    // super(false);
    this.parent = parent;
    this.gameProxy = gameProxy;
    // System.out.println("my p " + myPlanet);
    this.addCommand(cmdBack);
    // this.addCommand(cmdBuild);
    this.setCommandListener(this);
    setFullScreenMode(true);
    System.out.println("11111");
    en = Ground.getEnvironment(gameProxy.getMap(), gameProxy.getSaveName());
    System.out.println("21111");
    System.out.println(en);
    ENV = en;
    cm = new CurserManager(en, getHeight(), getWidth(), gameProxy);
    um = new UnitManager(en, getHeight(), getWidth());
    System.out.println("##1");
    cm.setUm(um);
    exec = true;
    myThread = new Thread(this);
    System.out.println("##2");

    try {
      JCageConfigurator.scoreTable = new Hashtable();
      System.out.println("Starting...");
      myThread.start();
      System.out.println("started...");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void showCamera() {

    try {

      releaseResources();
      player = Manager.createPlayer("capture://video");
      player.addPlayerListener(this);
      player.realize();

      videoControl = (VideoControl) player.getControl("VideoControl");
      aVideoCanvas = new VideoCanvas();
      aVideoCanvas.initControls(videoControl, player);

      aVideoCanvas.addCommand(CMD_RECORD);
      aVideoCanvas.addCommand(CMD_EXIT);
      aVideoCanvas.setCommandListener(this);
      parentMidlet.getDisplay().setCurrent(aVideoCanvas);

      player.start();
      contentType = player.getContentType();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void commandAction(Command c, Displayable d) {
    if (c == cmdCancel) {
      destroyView();
      return;
    }
    if (c == cmdOk) {
      try {
        int type = choiseType.getSelectedIndex();
        String value = textValue.getString();
        if (type == 2) value = PrivacyItem.subscrs[choiceSubscr.getSelectedIndex()];
        if (type != PrivacyItem.ITEM_ANY) if (value.length() == 0) return;
        // int order=Integer.parseInt(textOrder.getString());

        item.action = choiceAction.getSelectedIndex();
        item.type = type;
        item.value = value;
        // item.order=order;
        choiseStanzas.getSelectedFlags(item.stanzasSet);

        if (targetList != null)
          if (!targetList.rules.contains(item)) {
            targetList.addRule(item);
            item.order = targetList.rules.indexOf(item) * 10;
          }
        destroyView();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
예제 #8
0
 int getLineLength(int y) {
   try {
     return ((StringBuffer) vectorLines.elementAt(y)).length();
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in getLineLength()");
     return 0;
   }
 }
예제 #9
0
 public void runGame() {
   try {
     GameMain.music.stop();
     display.setCurrent(new mapCanvars(display, roleData, midlet));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #10
0
 StringBuffer getLine(int y) {
   try {
     return (StringBuffer) vectorLines.elementAt(y);
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in getLine()");
     return new StringBuffer("");
   }
 }
예제 #11
0
 boolean removeLine(int y) {
   try {
     vectorLines.removeElementAt(y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in removeLine()");
     return false;
   }
 }
예제 #12
0
 // 建立圖片
 public Image createImage(String pathImg) {
   img = null;
   try {
     img = Image.createImage(pathImg);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return img;
 }
예제 #13
0
 boolean setLine(int y, StringBuffer stringBuffer) {
   try {
     vectorLines.setElementAt(stringBuffer, y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in setLine()");
     return false;
   }
 }
예제 #14
0
  private boolean handleInhabitantUnitCreation(int timer) {
    // handle building creation

    // if (timer % 1000 != 0) return;

    System.out.println("%%%%%%%%%%%%%%% creatin IH U");
    int k = Math.abs(Ground.rand.nextInt()) % 3;
    System.out.println("k " + k);
    Unit setU = null;
    String type = "";
    if (k == 0) {
      type = JCageConfigurator.UNIT_GROUND_HUMAN_A;
    } else if (k == 1) {
      type = JCageConfigurator.UNIT_GROUND_HUMAN_B;
    } else {
      type = JCageConfigurator.UNIT_GROUND_HUMAN_C;
    }
    Enumeration e = JCageConfigurator.units.keys();
    while (e.hasMoreElements()) {
      String key = String.valueOf(e.nextElement());
      Unit bu = (Unit) JCageConfigurator.units.get(key);
      System.out.println(bu.getType());
      if (bu.getType().equals(type)) {
        setU = bu;
        break;
      }
    }
    // Point[] pts = en.getUnitInsetionPoints();
    // Point point = pts[Math.abs(Ground.rand.nextInt()) % pts.length];
    DynamicUnit bx =
        new DynamicUnit(
            en, gameProxy.getSaveName(), setU, MainMid.getClientConfigurator().user + "ene");

    long x = Math.abs(Ground.rand.nextInt()) % (GroundCell.W * Ground.width);
    long y = Math.abs(Ground.rand.nextInt()) % (GroundCell.H * Ground.height);
    int x1 = (int) x;
    int y1 = (int) y;
    if (bx.isAllowedCell(x1, y1)) {
      // possitioning the newly created unit
      bx.setX(x1);
      bx.setY(y1);

      System.out.println("Saving iH unit");
      try {
        BaseUnitService.getInstance().insert(bx);
        // System.out.println("Building saved");
        //            synchronized (Environment.unitHtLock) {
        en.units.put(bx.getUnitId(), bx);
        //            }
      } catch (Exception ex) {
        ex.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
      return true;
    }
    return false;
  }
예제 #15
0
 boolean addNewLine(int y) {
   try {
     vectorLines.insertElementAt(new StringBuffer(""), y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString());
     return false;
   }
 }
예제 #16
0
  public void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    try {
      g.drawImage(img, w / 2, h / 2, Graphics.VCENTER | Graphics.HCENTER);
    } catch (Exception e) {
      g.drawString(e.getMessage(), w / 2, h / 2, Graphics.BASELINE | Graphics.HCENTER);
    }
  }
예제 #17
0
  boolean copyLine(int sourceY, int destinationY) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(sourceY);
      // setLine
      vectorLines.setElementAt(currentLine, destinationY);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in copyLine()");
      return false;
    }
  }
예제 #18
0
 public void run() {
   while (true) {
     checkTimestamps();
     repaint();
     try {
       synchronized (this) {
         wait(50L);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
예제 #19
0
 // 鍵盤事件
 protected void keyPressed(int keyCode) {
   if (!init & page != -2) {
     switch (keyCode) {
       case -5: // 按下FIRE
         GameMain.music.msuicSound(0);
         try {
           changeMeunStart();
         } catch (Exception e) {
           e.printStackTrace();
         }
         break;
       case -1: // 按下UP
         GameMain.music.msuicSound(1);
         if (page == 0 || page == -1) {
           if (menustate <= 0) menustate = menuNum;
           menustate--;
         } else if (page == 2) {
           if (menustate <= 1) menustate = menuNum;
           menustate--;
         } else {
           if (menustate <= 2) menustate = menuNum;
           menustate--;
         }
         break;
       case -2: // 按下DOWN
         GameMain.music.msuicSound(1);
         if (page == 0 || page == -1) {
           if (menustate >= menuNum - 1) menustate = -1;
           menustate++;
         } else if (page == 2) {
           if (menustate >= 3) menustate = 0;
           menustate++;
         } else {
           if (menustate >= 3) menustate = 1;
           menustate++;
         }
         break;
       case -4: // 按下RIGHT
         GameMain.music.msuicSound(1);
         if (menustate == 2) menustate = 3;
         else if (menustate == 3) menustate = 2;
         break;
       case -3: // 按下LEFT
         GameMain.music.msuicSound(1);
         if (menustate == 2) menustate = 3;
         else if (menustate == 3) menustate = 2;
         break;
     }
     changeMeun();
   }
 }
예제 #20
0
 public LoginExample() {
   form = new Form("Sign in");
   userName = new TextField("LoginID:", "", 30, TextField.ANY);
   password = new TextField("Password:"******"", 30, TextField.PASSWORD);
   cancel = new Command("Cancel", Command.CANCEL, 2);
   login = new Command("Login", Command.OK, 2);
   try {
     img = Image.createImage("/logo.png");
     imge = Image.createImage("/front_left1_bad.png");
     img2 = Image.createImage("/Congratulations-1.png");
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
 }
예제 #21
0
  boolean removeFromLine(int xFrom, int xTo, int y) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.delete(xFrom, xTo);
      // setLine
      vectorLines.setElementAt(currentLine, y);
      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in removeFromLine()");
      return false;
    }
  }
 public void run() {
   if (playSnd) {
     try {
       for (int i = 0; i < tone.length(); ) {
         int note = (tone.charAt(i++) - 'A') + 12 * (tone.charAt(i++) - '0');
         int duration = 150;
         Manager.playTone(note, duration, 100);
         Thread.sleep(duration);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
예제 #23
0
 // 畫面選單改變
 public void changePage() {
   try {
     switch (page) {
       case -1:
         spName.setVisible(false);
         spInterface.setFrame(1);
         drawDisplay();
         break;
       case 0: // 遊戲帳號輸入選單
         menustate = 0;
         spName.setVisible(true);
         spInterface.setFrame(2);
         spName.setFrame(0);
         drawDisplay();
         for (int i = 0; i < loginStr.length; i++) nowString[i] = loginStr[i];
         menuNum = loginStr.length; // MENU 數量
         // System.out.println(page);
         break;
       case 1: // 遊戲說明選單
         spInterface.setFrame(2);
         spName.setFrame(1);
         drawDisplay();
         for (int i = 2; i < nowString.length; i++) nowString[i] = gameInfo[i - 2];
         menuNum = loginStr.length;
         menustate = 2;
         break;
       case 2: // 遊戲姓名輸入選單
         spInterface.setFrame(2);
         spName.setFrame(2);
         spName.setVisible(true);
         drawDisplay();
         for (int i = 1; i < nowString.length; i++) nowString[i] = gameNameInp[i - 1];
         menuNum = loginStr.length;
         menustate = 1;
         break;
       case 3: // 遊戲角色建立成功選單
         spName.setVisible(false);
         spInterface.setFrame(3);
         drawDisplay();
         for (int i = 2; i < nowString.length; i++) nowString[i] = showGameUser[i - 2];
         menuNum = loginStr.length;
         menustate = 2;
         break;
     }
     drawMenu();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #24
0
  boolean updateToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.setCharAt(x - 1, ch);
      // setLine
      vectorLines.setElementAt(currentLine, y);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in updateToLine()");
      return false;
    }
  }
예제 #25
0
 /**
  * Muestra un mensaje de aviso del tipo que se le especifique
  *
  * @param tipo Es el tipo de mensaje a mostrar.<br>
  *     0 representa una excepción genérica<br>
  *     1 representa un intento de conexión fallido debido a que el servidor no ha aceptado nuestra
  *     petición<br>
  *     2 representa un error al escoger el dispositivo con el que conectarnos.
  * @param d Display sobre el que mostrar el mensaje
  * @param ex Es la excepción que ha provocado el mensaje de error (en caso de que se muestre un
  *     mensaje debido a una excepción)
  */
 public void mostrarAlarma(int tipo, Display d, Exception ex) {
   Alert alerta = null;
   if (tipo == 0) {
     alerta =
         new Alert(
             "ERROR EN LA APLICACION",
             "Se ha producido el siguiente error en la aplicación:\n" + ex.getMessage(),
             null,
             AlertType.ERROR);
   } else if (tipo == 1) {
     alerta =
         new Alert(
             "PETICIÓN RECHAZADA",
             "El usuario el que queria recibir cartas ha rechazado su conexión",
             null,
             AlertType.INFO);
   } else if (tipo == 2) {
     alerta =
         new Alert(
             "IMPLOSIBLE CONEXIÓN",
             "Este dispositivo no ofrece la posibilidad de intercambiar cartas con usted",
             null,
             AlertType.INFO);
   }
   alerta.setTimeout(Alert.FOREVER);
   display.setCurrent(alerta, this);
 }
예제 #26
0
  /** Save the URL setting the user entered in to the urlTextBox. */
  private void saveURLSetting() {
    String temp;
    Exception ex;

    temp = urlTextBox.getString();

    ex = GraphicalInstaller.saveSettings(temp, MIDletSuite.INTERNAL_SUITE_ID);
    if (ex != null) {
      displayException(Resource.getString(ResourceConstants.EXCEPTION), ex.toString());
      return;
    }

    defaultInstallListUrl = temp;

    displaySuccessMessage(Resource.getString(ResourceConstants.AMS_MGR_SAVED));
  }
예제 #27
0
  boolean shiftDown(int y) {
    try {
      addNewLine(getLinesCount() + 1 - 1);

      // tricky! -1 because of beginning from 0, -1 because next line, -1 because getLinesCount() is
      // already updated (+1)
      for (int sourceY = getLinesCount() - 2; sourceY >= y; sourceY--) // -1
      {
        copyLine(sourceY, sourceY + 1);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in shiftDown()");
      return false;
    }
  }
예제 #28
0
 private void handleException(Exception e) {
   Alert a = new Alert("Exception", e.toString(), null, null);
   a.setTimeout(Alert.FOREVER);
   // Throw with a proper JR alert. Crash for now until someone fixes this.
   // mDisplay.setCurrent(a, mMainForm);
   throw new RuntimeException(
       "Snapper MIDLlet exception needs to be displayed as an alert, but fixed to use j2me properly");
 }
예제 #29
0
  /**
   * Called by a system to indicated that a command has been invoked on a particular displayable.
   *
   * @param command the Command that was invoked
   * @param displayable the Displayable where the command was invoked
   */
  public void commandAction(Command command, Displayable displayable) {
    // GEN-END:|7-commandAction|0|7-preCommandAction
    // write pre-action user code here
    if (displayable == inputForm) { // GEN-BEGIN:|7-commandAction|1|37-preAction
      if (command == exitCommand) { // GEN-END:|7-commandAction|1|37-preAction
        // write pre-action user code here
        exitMIDlet(); // GEN-LINE:|7-commandAction|2|37-postAction
        // write post-action user code here
      } else if (command == okCommand) { // GEN-LINE:|7-commandAction|3|25-preAction
        // write pre-action user code here
        int numInput = Integer.parseInt(getInputNumber().getString());
        if (numInput > this.randomNum) {
          this.tip = "oh, looks like the number you chose is bigger than the one I have";
        } else if (numInput < this.randomNum) {
          this.tip = "oh, looks like the number you chose is smaller than the one I have";
        } else {
          this.tip =
              "Congratulations, you've got the right number ("
                  + Integer.toString(this.randomNum)
                  + ")! :D";
        }

        this.attempts++;

        switchDisplayable(null, getResultForm()); // GEN-LINE:|7-commandAction|4|25-postAction
        // write post-action user code here
        try {
          resultText.setText(this.tip);
          attemptsText.setText("Number of attempts: " + Integer.toString(this.attempts));
        } catch (Exception e) {
          e.printStackTrace();
        }
      } // GEN-BEGIN:|7-commandAction|5|40-preAction
    } else if (displayable == resultForm) {
      if (command == backCommand) { // GEN-END:|7-commandAction|5|40-preAction
        // write pre-action user code here
        switchDisplayable(null, getInputForm()); // GEN-LINE:|7-commandAction|6|40-postAction
        // write post-action user code here
      } else if (command == exitCommand1) { // GEN-LINE:|7-commandAction|7|42-preAction
        // write pre-action user code here
        exitMIDlet(); // GEN-LINE:|7-commandAction|8|42-postAction
        // write post-action user code here
      } // GEN-BEGIN:|7-commandAction|9|7-postCommandAction
    } // GEN-END:|7-commandAction|9|7-postCommandAction
    // write post-action user code here
  } // GEN-BEGIN:|7-commandAction|10|
예제 #30
0
  public void commandAction(Command command, Displayable displayable) {
    if (command == cmdBack) {
      exec = false;
      try {
        BaseUnitService.getInstance().insertOrUpdate(en.units);
        BaseBuildingService.getInstance().insertOrUpdate(en.buildings);
        Thread.sleep(1000);
      } catch (Exception e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
      while (finished) {}

      ENV = null;
      MainMid.getClientConfigurator().displayParent();
    }
  }