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); } }
/** * We have to provide this method due to "do not do network operation in command listener method" * restriction, which is caused by crooked midp design. * * <p>This method is called by BTImageClient after it is done with bluetooth initialization and * next screen is ready to appear. */ void completeInitialization(boolean isBTReady) { // bluetooth was initialized successfully. if (isBTReady) { StringItem si = new StringItem("Ready for images search!", null); si.setLayout(StringItem.LAYOUT_CENTER | StringItem.LAYOUT_VCENTER); mainScreen.append(si); Display.getDisplay(parent).setCurrent(mainScreen); return; } // something wrong Alert al = new Alert("Error", "Can't initialize bluetooth", null, AlertType.ERROR); al.setTimeout(DemoMIDlet.ALERT_TIMEOUT); Display.getDisplay(parent).setCurrent(al, parent.getDisplayable()); }
/** * 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|
public void commandAction(Command c, Item it) { // #debug info logger.info("Command " + c + " Item " + it); Hashtable tags = osmentity.getTags(); if (c == REMOVE_CMD) { tags.remove(((StringItem) it).getLabel()); setupScreen(); } if (c == EDIT_CMD) { for (int i = 0; i < this.size(); i++) { if (this.get(i) == it) { StringItem si = (StringItem) it; this.delete(i); TextField tf = new TextField(it.getLabel(), si.getText(), 100, TextField.ANY); tf.addCommand(OK_CMD); tf.setItemCommandListener(this); this.insert(i, tf); Display.getDisplay(GpsMid.getInstance()).setCurrentItem(tf); } } } if (c == OK_CMD) { if (addTag) { tags.put( ((TextField) this.get(this.size() - 2)).getString(), ((TextField) this.get(this.size() - 1)).getString()); } else { for (int i = 0; i < this.size(); i++) { if (this.get(i) == it) { TextField tf = (TextField) it; tags.put(it.getLabel(), tf.getString()); } } } addTag = false; setupScreen(); } }
public SettingsForm(MainForm mf) { super("HipoqihPlugin"); setCommandListener(this); mainForm = mf; labelUser.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_2); this.append(labelUser); textUser.setLayout( Item.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2); this.append(textUser); labelPass.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_2); this.append(labelPass); textPass.setLayout( Item.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2); this.append(textPass); labelPeriod.setLayout( Item.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2); this.append(labelPeriod); textPeriod.setLayout( Item.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2); this.append(textPeriod); this.addCommand(cmdSave); this.addCommand(cmdCancel); }
public void crash(Throwable t) { message.setText(t.toString()); display.setCurrent(crashForm); }