Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need an <a href="http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Alert.html" rel="nofollow noreferrer">Alert</a>:</p> <blockquote> <p>An alert is a screen that shows data to the user and waits for a certain period of time before proceeding to the next Displayable. An alert can contain a text string and an image. The intended use of Alert is to inform the user about errors and other exceptional conditions.</p> </blockquote> <p>With 2 <a href="http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Command.html" rel="nofollow noreferrer">commands</a> ("Yes"/"No" in your case):</p> <blockquote> <p>If there are two or more Commands present on the Alert, it is automatically turned into a modal Alert, and the timeout value is always FOREVER. The Alert remains on the display until a Command is invoked.</p> </blockquote> <p>These are built-in classes supported in MIDP 1.0 and higher. Also your code snippet will never work. Such an API would need to block the calling thread awaiting for the user to select and answer. This goes exactly in the opposite direction of the UI interaction model of MIDP, which is based in callbacks and delegation. You need to provide your own class, implementing <a href="http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/CommandListener.html" rel="nofollow noreferrer">CommandListener</a>, and prepare your code for asynchronous execution.</p> <p>Here is an (untested!) example class based on Alert:</p> <pre><code>public class MyPrompter implements CommandListener { private Alert yesNoAlert; private Command softKey1; private Command softKey2; private boolean status; public MyPrompter() { yesNoAlert = new Alert("Attention"); yesNoAlert.setString("Are you sure?"); softKey1 = new Command("No", Command.BACK, 1); softKey2 = new Command("Yes", Command.OK, 1); yesNoAlert.addCommand(softKey1); yesNoAlert.addCommand(softKey2); yesNoAlert.setCommandListener(this); status = false; } public Displayable getDisplayable() { return yesNoAlert; } public boolean getStatus() { return status; } public void commandAction(Command c, Displayable d) { status = c.getCommandType() == Command.OK; // maybe do other stuff here. remember this is asynchronous } }; </code></pre> <p>To use it (again, untested and on top of my head):</p> <pre><code>MyPrompter prompt = new MyPrompter(); Display.getDisplay(YOUR_MIDLET_INSTANCE).setCurrent(prompt.getDisplayable()); </code></pre> <p>This code will make the prompt the current displayed form in your app, but it <em>won't block your thread</em> like in the example you posted. You need to continue running and wait for a commandAction invocation.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload