예제 #1
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);
  }
예제 #2
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();
    }
  }
예제 #4
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();
   }
 }
예제 #5
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));
  }
예제 #6
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|
예제 #7
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|
예제 #8
0
  /** Ask the user for the URL. */
  private void getUrl() {
    try {
      if (urlTextBox == null) {
        urlTextBox =
            new TextBox(
                Resource.getString(ResourceConstants.AMS_DISC_APP_WEBSITE_INSTALL),
                defaultInstallListUrl,
                1024,
                TextField.ANY);
        urlTextBox.addCommand(endCmd);
        urlTextBox.addCommand(saveCmd);
        urlTextBox.addCommand(discoverCmd);
        urlTextBox.setCommandListener(this);
      }

      display.setCurrent(urlTextBox);
    } catch (Exception ex) {
      displayException(Resource.getString(ResourceConstants.EXCEPTION), ex.toString());
    }
  }
예제 #9
0
  /**
   * Install a suite.
   *
   * @param selectedSuite index into the installList
   */
  private void installSuite(int selectedSuite) {
    MIDletStateHandler midletStateHandler = MIDletStateHandler.getMidletStateHandler();
    MIDletSuite midletSuite = midletStateHandler.getMIDletSuite();
    SuiteDownloadInfo suite;
    String displayName;

    suite = (SuiteDownloadInfo) installList.elementAt(selectedSuite);

    midletSuite.setTempProperty(null, "arg-0", "I");
    midletSuite.setTempProperty(null, "arg-1", suite.url);
    midletSuite.setTempProperty(null, "arg-2", suite.label);

    displayName = Resource.getString(ResourceConstants.INSTALL_APPLICATION);
    try {
      midletStateHandler.startMIDlet("com.sun.midp.installer.GraphicalInstaller", displayName);
      /*
       * Give the create MIDlet notification 1 second to get to
       * AMS.
       */
      Thread.sleep(1000);
      notifyDestroyed();
    } catch (Exception ex) {
      StringBuffer sb = new StringBuffer();

      sb.append(displayName);
      sb.append("\n");
      sb.append(Resource.getString(ResourceConstants.ERROR));
      sb.append(": ");
      sb.append(ex.toString());

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.AMS_CANNOT_START),
              sb.toString(),
              null,
              AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      display.setCurrent(a, urlTextBox);
    }
  }
예제 #10
0
 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>
   }
 }
예제 #11
0
    /**
     * Get the list of suites for the user to install. The suites that are listed are the links on a
     * web page that end with .jad.
     */
    public void run() {
      StreamConnection conn = null;
      InputStreamReader in = null;
      String errorMessage;
      long startTime;

      startTime = System.currentTimeMillis();

      try {
        parent.displayProgressForm(
            Resource.getString(ResourceConstants.AMS_DISC_APP_GET_INSTALL_LIST),
            "",
            url,
            0,
            Resource.getString(ResourceConstants.AMS_GRA_INTLR_CONN_GAUGE_LABEL));
        conn = (StreamConnection) Connector.open(url, Connector.READ);
        in = new InputStreamReader(conn.openInputStream());
        try {
          parent.updateProgressForm(
              "", 0, Resource.getString(ResourceConstants.AMS_DISC_APP_GAUGE_LABEL_DOWNLOAD));

          parent.installList = SuiteDownloadInfo.getDownloadInfoFromPage(in);

          if (parent.installList.size() > 0) {
            parent.installListBox =
                new List(
                    Resource.getString(ResourceConstants.AMS_DISC_APP_SELECT_INSTALL),
                    Choice.IMPLICIT);

            // Add each suite
            for (int i = 0; i < parent.installList.size(); i++) {
              SuiteDownloadInfo suite = (SuiteDownloadInfo) installList.elementAt(i);
              parent.installListBox.append(suite.label, (Image) null);
            }

            parent.installListBox.addCommand(parent.backCmd);
            parent.installListBox.addCommand(parent.installCmd);
            parent.installListBox.setCommandListener(parent);

            /*
             * We need to prevent "flashing" on fast development
             * platforms.
             */
            while (System.currentTimeMillis() - parent.lastDisplayChange
                < GraphicalInstaller.ALERT_TIMEOUT) ;

            parent.display.setCurrent(parent.installListBox);
            return;
          }

          errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CHECK_URL_MSG);
        } catch (IllegalArgumentException ex) {
          errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_URL_FORMAT_MSG);
        } catch (Exception ex) {
          errorMessage = ex.getMessage();
        }
      } catch (Exception ex) {
        errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CONN_FAILED_MSG);
      } finally {
        if (parent.progressForm != null) {
          // end the background thread of progress gauge.
          Gauge progressGauge = (Gauge) parent.progressForm.get(parent.progressGaugeIndex);
          progressGauge.setValue(Gauge.CONTINUOUS_IDLE);
        }

        try {
          conn.close();
          in.close();
        } catch (Exception e) {
          if (Logging.REPORT_LEVEL <= Logging.WARNING) {
            Logging.report(Logging.WARNING, LogChannels.LC_AMS, "close threw an Exception");
          }
        }
      }

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.ERROR), errorMessage, null, AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      parent.display.setCurrent(a, parent.urlTextBox);
    }
예제 #12
0
파일: Game.java 프로젝트: skjApp/J2ME
  // 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();
    }
  }