예제 #1
1
  public void startApp() {
    if (mDisplay == null) {
      mDisplay = Display.getDisplay(this);
    }

    if (mMenu == null) {
      mMenu = new List("MohairMIDlet", List.IMPLICIT);
      mMenu.append(kQuerySlots, null);
      mMenu.append(kSignTest, null);

      mBackCommand = new Command("Back", Command.BACK, 0);
      mExitCommand = new Command("Exit", Command.EXIT, 0);

      mMenu.addCommand(mExitCommand);
      mMenu.setCommandListener(this);
    }

    mDisplay.setCurrent(mMenu);
  }
예제 #2
1
  public void commandAction(Command c, Displayable d) {
    if (c == mExitCommand) {
      destroyApp(true);
      notifyDestroyed();
    } else if ((c == List.SELECT_COMMAND) && (d == mMenu)) {
      int selection = mMenu.getSelectedIndex();
      String item = "[none]";

      if ((selection >= 0) && (selection < mMenu.size())) {
        item = mMenu.getString(selection);
      }

      if (item == kQuerySlots) {
        Form slotList = new Form("Slots");
        String slots = System.getProperty("microedition.smartcardslots");
        int index = 0;

        while (index < slots.length()) {
          String slot;
          int comma = slots.indexOf(',', index);

          if (comma == -1) {
            slot = slots.substring(index).trim();
            index = slots.length();
          } else {
            slot = slots.substring(index, comma).trim();
            index = comma + 1;
          }

          StringItem slotItem = new StringItem(null, slot);
          slotItem.setLayout(Item.LAYOUT_2 | Item.LAYOUT_NEWLINE_AFTER);
          slotList.append(slotItem);
        }

        slotList.addCommand(mBackCommand);
        slotList.setCommandListener(this);
        mDisplay.setCurrent(slotList);
      } else if (item == kSignTest) {
        System.out.println("Starting sign test...");

        /*
        try {
          CMSMessageSignatureService.sign(
            "This is the message to sign",
            CMSMessageSignatureService.SIG_INCLUDE_CONTENT |
                CMSMessageSignatureService.SIG_INCLUDE_CERTIFICATE,
            null,
            "This is the prompt");
        }
        catch (Exception e) {
          System.out.println("sign() barfed: " + e);
        }*/
        new Thread() {
          public void run() {
            fromSpecification();
            System.out.println("Sign test finished.");
          }
        }.start();
      }
    } else if (c == mBackCommand) {
      mDisplay.setCurrent(mMenu);
    }
  }