示例#1
1
  public void startApp() {
    // Create Record Store
    try {
      rs = RecordStore.openRecordStore("myrs", true);
    } catch (RecordStoreException e) {
    }

    dsp = Display.getDisplay(this);
    listMenu.setCommandListener(this);
    listMenu.addCommand(cmdExit);
    dsp.setCurrent(listMenu);
  }
示例#2
1
  public void commandAction(Command c, Displayable d) {

    if (c == List.SELECT_COMMAND) {
      List down = (List) dsp.getCurrent();
      String title = down.getTitle();

      if (title.equals("Menu:")) {
        switch (down.getSelectedIndex()) {
          case 0:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              addRecordForm();
              break;
            }
          case 1:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              showAllRecordForm();
              break;
            }
          case 2:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              showFirstRecord();
              break;
            }
          case 3:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              getNumberRecord();
              break;
            }
          case 4:
            {
              System.out.println("Stisknul jsi " + down.getString(down.getSelectedIndex()));
              editRecord(1);
              break;
            }
        }
      }
    }

    if (c == cmdExit) {
      // rs.closeRecordStore();
      notifyDestroyed();
    }
    if (c == cmdMenu) {
      dsp.setCurrent(listMenu);
    }
    if (c == cmdEdit) {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      // filtr; filtr dostane pri vytvoreni stream jako parametr;
      // format dat nezavisly na platforme
      // definuje metodu write() pro vsechny primitivni typy
      DataOutputStream dout = new DataOutputStream(buffer);
      // byte [] data = txf.getString().getBytes();
      try {
        dout.writeUTF(txfName.getString());
        dout.writeInt(Integer.valueOf(txfNumber.getString()).intValue());
        txfName.delete(0, txfName.size());
        txfNumber.delete(0, txfNumber.size());
        // zapise buffer do streamu
        dout.flush();
        // prevod ByteArrayOutputStream na pole bytu;
        byte[] b = buffer.toByteArray();
        rs.setRecord(1, b, 0, b.length);
      } catch (Exception e) {
      } finally {
        try {
          dout.close();
        } catch (Exception e2) {
        }
      }
    }
    if (c == cmdAdd) {
      // vystupni stream; zapisuje do buferu v pamžti
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      // filtr; filtr dostane pri vytvoreni stream jako parametr;
      // format dat nezavisly na platforme
      // definuje metodu write() pro vsechny primitivni typy
      DataOutputStream dout = new DataOutputStream(buffer);
      // byte [] data = txf.getString().getBytes();
      try {
        dout.writeUTF(txfName.getString());
        dout.writeInt(Integer.valueOf(txfNumber.getString()).intValue());
        txfName.delete(0, txfName.size());
        txfNumber.delete(0, txfNumber.size());
        // zapise buffer do streamu
        dout.flush();
        // prevod ByteArrayOutputStream na pole bytu;
        byte[] b = buffer.toByteArray();
        rs.addRecord(b, 0, b.length);
      } catch (Exception e) {
      } finally {
        try {
          dout.close();
        } catch (Exception e2) {
        }
      }
    }
  }
示例#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
  /**
   * Display the connecting form to the user, let call set actions.
   *
   * @param action action to put in the form's title
   * @param name name to in the form's title
   * @param url URL of a JAD
   * @param size 0 if unknown, else size of object to download in K bytes
   * @param gaugeLabel label for progress gauge
   * @return displayed form
   */
  private Form displayProgressForm(
      String action, String name, String url, int size, String gaugeLabel) {
    Gauge progressGauge;
    StringItem urlItem;

    progressForm = new Form(null);

    progressForm.setTitle(action + " " + name);

    if (size <= 0) {
      progressGauge = new Gauge(gaugeLabel, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);
    } else {
      progressGauge = new Gauge(gaugeLabel, false, size, 0);
    }

    progressGaugeIndex = progressForm.append(progressGauge);

    if (url == null) {
      urlItem = new StringItem("", "");
    } else {
      urlItem = new StringItem(Resource.getString(ResourceConstants.AMS_WEBSITE) + ": ", url);
    }

    progressUrlIndex = progressForm.append(urlItem);

    display.setCurrent(progressForm);
    lastDisplayChange = System.currentTimeMillis();

    return progressForm;
  }
示例#5
0
  /**
   * Display an exception to the user, with a done command.
   *
   * @param title exception form's title
   * @param message exception message
   */
  private void displayException(String title, String message) {
    Alert a = new Alert(title, message, null, AlertType.ERROR);

    a.setTimeout(Alert.FOREVER);
    a.setCommandListener(this);

    display.setCurrent(a);
  }
示例#6
0
 public void startApp() {
   textBox = new TextBox("Ophone", "\n", 512, TextField.UNEDITABLE);
   OxportMIDlet.addtext("Listo para exportar servicios...");
   textBox.addCommand(exitCom);
   textBox.addCommand(playCom);
   textBox.addCommand(initCom);
   textBox.setCommandListener(this);
   display.setCurrent(textBox);
 }
示例#7
0
 public void addRecordForm() {
   fmAddRecord = new Form("Add Record");
   txfName = new TextField("Name", "", 10, TextField.ANY);
   txfNumber = new TextField("Number", "", 10, TextField.NUMERIC);
   fmAddRecord.append(txfName);
   fmAddRecord.append(txfNumber);
   fmAddRecord.addCommand(cmdAdd);
   fmAddRecord.addCommand(cmdMenu);
   fmAddRecord.setCommandListener(this);
   dsp.setCurrent(fmAddRecord);
 }
示例#8
0
 public void getNumberRecord() {
   fmNumbers = new Form("Number of Records");
   int number = 0;
   try {
     number = rs.getNumRecords();
   } catch (Exception e) {
   }
   fmNumbers.append("Numbers of Records: " + number);
   dsp.setCurrent(fmNumbers);
   fmNumbers.setCommandListener(this);
   fmNumbers.addCommand(cmdMenu);
 }
示例#9
0
 /**
  * Respond to a command issued on any Screen.
  *
  * @param c command activated by the user
  * @param s the Displayable the command was on.
  */
 public void commandAction(Command c, Displayable s) {
   if (c == discoverCmd) {
     // user wants to discover the suites that can be installed
     discoverSuitesToInstall(urlTextBox.getString());
   } else if (s == installListBox && (c == List.SELECT_COMMAND || c == installCmd)) {
     installSuite(installListBox.getSelectedIndex());
   } else if (c == backCmd) {
     display.setCurrent(urlTextBox);
   } else if (c == saveCmd) {
     saveURLSetting();
   } else if (c == endCmd || c == Alert.DISMISS_COMMAND) {
     // goto back to the manager midlet
     notifyDestroyed();
   }
 }
示例#10
0
  /**
   * Alert the user that an action was successful.
   *
   * @param successMessage message to display to user
   */
  private void displaySuccessMessage(String successMessage) {
    Image icon;
    Alert successAlert;

    icon = GraphicalInstaller.getImageFromInternalStorage("_dukeok8");

    successAlert = new Alert(null, successMessage, icon, null);

    successAlert.setTimeout(GraphicalInstaller.ALERT_TIMEOUT);

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

    lastDisplayChange = System.currentTimeMillis();
    display.setCurrent(successAlert);
  }
示例#11
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());
    }
  }
示例#12
0
  public void commandAction(Command c, Displayable s) {
    if (c == exitCom) {
      destroyApp(true);
      notifyDestroyed();

    } else if (c == initCom) {
      if (ox == null) {
        textBox.insert("Exportando...\n", textBox.size());
        ox = new Oxport();
        ox.start();
      }
    } else if (c == playCom) {
      if ((ox == null) || (ox.getOServer() == null)) addtext("Playground need a OServer running");
      else {
        if (playground == null) playground = new PlayGround(this);
        display.setCurrent(playground);
      }
    } else {
    }
  }
示例#13
0
  public void showFirstRecord() {
    fmFirstRecord = new Form("First Record");
    String name = "Nenacetl jsem";
    int number = 0;
    try {
      byte[] record = rs.getRecord(1);
      ByteArrayInputStream buffer = new ByteArrayInputStream(record);
      DataInputStream dis = new DataInputStream(buffer);
      name = dis.readUTF();
      number = dis.readInt();
      dis.close();
    } catch (Exception e) {
    }

    fmFirstRecord.append(name + " " + String.valueOf(number));
    // fmFirstRecord.append(String.valueOf(number));
    fmFirstRecord.setCommandListener(this);
    fmFirstRecord.addCommand(cmdMenu);
    dsp.setCurrent(fmFirstRecord);
  }
示例#14
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);
    }
  }
示例#15
0
 public void editRecord(int record_num) {
   fmEditRecord = new Form("Edit Record");
   String name = "Nenacetl jsem";
   int number = 0;
   try {
     byte[] record = rs.getRecord(record_num);
     ByteArrayInputStream buffer = new ByteArrayInputStream(record);
     DataInputStream dis = new DataInputStream(buffer);
     name = dis.readUTF();
     number = dis.readInt();
     dis.close();
   } catch (Exception e) {
   }
   txfName = new TextField("Name", name, 10, TextField.ANY);
   txfNumber = new TextField("Number", String.valueOf(number), 10, TextField.NUMERIC);
   fmEditRecord.append(txfName);
   fmEditRecord.append(txfNumber);
   fmEditRecord.addCommand(cmdEdit);
   fmEditRecord.addCommand(cmdMenu);
   fmEditRecord.setCommandListener(this);
   dsp.setCurrent(fmEditRecord);
 }
 public void startApp() {
   display.setCurrent(form);
 }
示例#17
0
 public void exitPlay() {
   display.setCurrent(textBox);
 }