/** * 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 crash(Throwable t) { message.setText(t.toString()); display.setCurrent(crashForm); }