Пример #1
0
 public void startApp() {
   if (mForm == null) {
     mForm = new Form(mAppID);
     mNumberEntry = new TextField("Connect To:", null, 256, TextField.PHONENUMBER);
     try {
       mInitialImage = Image.createImage(DEFAULT_IMAGE);
     } catch (Exception e) {
       System.out.println("start app err");
       e.printStackTrace();
     }
     mColorSquare =
         new ImageItem(null, mInitialImage, ImageItem.LAYOUT_DEFAULT, "waiting for image");
     mForm.append(mNumberEntry);
     mForm.append(mColorSquare);
     mForm.addCommand(mRedCommand);
     mForm.addCommand(mExitCommand);
     mForm.addCommand(mBlueCommand);
     mForm.setCommandListener(this);
   }
   Display.getDisplay(this).setCurrent(mForm);
   try {
     conn = (MessageConnection) Connector.open("mms://:" + mAppID);
     conn.setMessageListener(this);
   } catch (Exception e) {
     System.out.println("" + e);
   }
   if (conn != null) {
     startReceive();
   }
 }
  public void startApp() {
    try {
      ImplementationFactory.setInstance(new MobrizImplementationFactory());
      Display.init(this);
      InputStream stream = getClass().getResourceAsStream("/dhismobile.res");
      Resources theme = Resources.open(stream);
      UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
      // <editor-fold defaultstate="collapsed" desc=" Initialize Record Store ">
      new Thread(
              new Runnable() {

                public void run() {
                  try {
                    // <editor-fold defaultstate="collapsed" desc=" Check if store exists ">
                    dataStore = RecordStore.openRecordStore("dataStore", true);
                    if (dataStore.getNumRecords() == 0) {
                      firstRun = true;
                    } else {
                      firstRun = false;
                    }
                    // </editor-fold>
                    // <editor-fold defaultstate="collapsed" desc=" Create RecordStore with 90 rows
                    // ">
                    if (firstRun) {
                      for (int i = 0; i < 90; i++) {
                        try {
                          dataStore.addRecord("".getBytes(), 0, "".getBytes().length);
                        } catch (RecordStoreException rsex) {
                          rsex.printStackTrace();
                        }
                      }
                    } // </editor-fold>
                    // <editor-fold defaultstate="collapsed" desc=" Check if any previous msg Stored
                    // ">
                    else {
                      if (dataStore.getRecord(10) != null) {
                        String checkSaved = new String(dataStore.getRecord(10));
                        if (checkSaved.equals("true")) {
                          savedMsg = true;
                        }
                      }
                    }
                    // </editor-fold>
                  } catch (RecordStoreException ex) {
                    ex.printStackTrace();
                  }
                }
              })
          .start();
      // </editor-fold>
      showSplashScreen();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Пример #3
0
 public void commandAction(Command command, Displayable displayable) {
   if (Commands.exitCommand.equals(command)) {
     try {
       this.engine.destroy();
       this.engine = null;
       this.canvas.resetScreens();
       destroyApp(true);
       notifyDestroyed();
     } catch (Exception e) {
       e.printStackTrace();
     }
   } else if (Commands.menuCommand.equals(command)) {
     this.engine.state = Engine.MENU;
     this.engine.destroyStages();
   }
 }
Пример #4
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|
Пример #5
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 == LoginForm) { // GEN-BEGIN:|7-commandAction|1|65-preAction
      if (command == CreateAgentandJoin) { // GEN-END:|7-commandAction|1|65-preAction
        // write pre-action user code here
        String name = UserAgentNameTF.getString();
        String strAgentClassName = "au.edu.latrobe.placecomm.agents.MobileUserAgent";
        try {
          MicroRuntime.startAgent(name, strAgentClassName, null);
          // write post-action user code here
        } catch (Exception ex) {
          ex.printStackTrace();
        }
        // GEN-LINE:|7-commandAction|2|65-postAction
        // write post-action user code here
      } else if (command == CreateContainer) { // GEN-LINE:|7-commandAction|3|63-preAction
        // write pre-action user code here

        Thread t =
            new Thread() {
              public void run() {
                myStartGoOnline();
              }
            };
        t.start();

        // GEN-LINE:|7-commandAction|4|63-postAction
        // write post-action user code here
      } else if (command == OfflineMode) { // GEN-LINE:|7-commandAction|5|28-preAction
        // write pre-action user code here
        // GEN-LINE:|7-commandAction|6|28-postAction
        // write post-action user code here
      } else if (command == exitCommand) { // GEN-LINE:|7-commandAction|7|17-preAction
        // write pre-action user code here
        exitMIDlet(); // GEN-LINE:|7-commandAction|8|17-postAction
        // write post-action user code here
      } else if (command == okCommand) { // GEN-LINE:|7-commandAction|9|20-preAction
        // write pre-action user code here
        // GEN-LINE:|7-commandAction|10|20-postAction
        // write post-action user code here
      } // GEN-BEGIN:|7-commandAction|11|7-postCommandAction
    } // GEN-END:|7-commandAction|11|7-postCommandAction
    // write post-action user code here
  } // GEN-BEGIN:|7-commandAction|12|
 private void startSession() {
   SipClientConnection scc = null;
   try {
     // <i><b>start a listener for incoming requests</b></i>
     startListener();
     // <i><b>open SIP connection with remote user</b></i>
     scc = (SipClientConnection) Connector.open(address.getString());
     scc.setListener(this);
     // <i><b>initialize INVITE request</b></i>
     scc.initRequest("INVITE", scn);
     scc.setHeader("Content-Length", "" + sdp.length());
     scc.setHeader("Content-Type", "application/sdp");
     OutputStream os = scc.openContentOutputStream();
     os.write(sdp.getBytes());
     os.close(); // <i><b>close and send</b></i>
     str = new StringItem("Inviting... ", scc.getHeader("To"));
     form.append(str);
   } catch (Exception ex) {
     ex.printStackTrace();
     // <i><b>handle IOException</b></i>
   }
 }
Пример #7
0
  // for initilization purpose and call in the Game() constructor
  public void init() {
    try {
      this.userWins = 0;
      this.compWins = 0;

      this.colSelected = 0;
      this.rowSelected = 0;
      // repaint() ;

      // Getting the maximum width and height of the Canvas
      this.maxX = this.getWidth();
      this.maxY = this.getHeight();

      this.alert =
          new Alert(
              "Score",
              "User  "
                  + String.valueOf(this.userWins)
                  + "\nDevice  "
                  + String.valueOf(this.compWins),
              null,
              AlertType.INFO);

      this.animated = this.parent.getAnimate();

      // Initilizing the Command
      this.score = new Command("Score", Command.ITEM, 2);
      this.addCommand(this.score);
      // this.setCommandListener( this ) ;

      this.newG = new Command("New", Command.ITEM, 1);
      this.addCommand(this.newG);

      this.addCommand(this.back);

      this.setCommandListener(this);

      this.random = new Random();

      // Settings the framem variable
      this.frame = 0;

      this.sq = new int[3][4];

      // Initializing the sq[][] array to -1
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          this.sq[i][j] = -1;
        }
      }

      // Setting the userSymbol
      if (this.userSymbol == -1) {
        this.userSymbol = 0;
      } else if (this.userSymbol == 0) {
        this.userSymbol = 1;
      } else if (this.userSymbol == 1) {
        this.userSymbol = 0;
      }

      // Setting the compSymbol
      if (this.compSymbol == -1) {
        this.compSymbol = 1;
      } else if (this.compSymbol == 0) {
        this.compSymbol = 1;
      } else if (this.compSymbol == 1) {
        this.compSymbol = 0;
      }

      // Declaring timer and timertask
      TimerTask task =
          new TimerTask() {
            public void run() {
              if (frame == 0) {
                if (animated == true) {
                  frame = 1;
                }
              } else if (frame == 1) {
                if (animated == true) {
                  frame = 0;
                }
              }

              // Checking whether all chances are finished
              int c = 0;
              for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                  if (sq[i][j] == -1) {
                    c++;
                  }
                }
              }

              if (c == 0) {
                alert =
                    new Alert(
                        "Draw !",
                        "User  "
                            + String.valueOf(userWins)
                            + "\nDevice  "
                            + String.valueOf(compWins),
                        null,
                        AlertType.INFO);
                parent.setDisplayable(alert);
                newGame();
              }

              repaint();
            }
          };

      timer = new Timer();
      timer.scheduleAtFixedRate(task, 400, 400);

      // Initialising images

      if (this.maxX < 150 && this.maxY < 150) {
        this.imgWidth = 16;
        this.imgHeight = 16;
        this.crossImage = Image.createImage("/cross16.png");
        this.zeroImage = Image.createImage("/naught16.png");
      } else {
        this.imgWidth = 32;
        this.imgHeight = 32;
        this.crossImage = Image.createImage("/cross32.png");
        this.zeroImage = Image.createImage("/naught32.png");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }