Can anyone help me with implementing a blocking modal dialog in MIDP1.0?

Hi guys.. I'm posting because I dont know much about the way java ui runs with respect to threading.. Infact, I dont know how many threads a J2ME app would run to write hello world on the screen, or how I would pause them but maintain responsiveness.
I read this thread: SonyEricssonDevelopers
which gave me a few pointers.
I then wrote this code, that doesnt work:
public class QuestionForm extends Form implements CommandListener {
    private static Object lock = new Object();
    private String answer = null;
    private String defaultAnswer = null;
    public QuestionForm(String message, String answer1, String answer2) {
        super("");
        this.defaultAnswer = answer1;
        this.append(new StringItem(message, ""));
        this.addCommand(new Command(answer1, Command.BACK, 1));
        this.addCommand(new Command(answer2, Command.BACK, 2));
        this.setCommandListener(this);
    public String ask(){
        answer = null;
        //static accessor for display
        GoText.display.setCurrent(this);
        synchronized(lock){
            try{
                while(answer == null)
                    wait();
            }catch(Exception ex){
                answer = defaultAnswer;
        return answer;
    public void commandAction(Command c, Displayable d) {
        answer = c.getLabel();
        synchronized(lock){
            notifyAll();
}I want to be able to say:
//some code.. oh we need to ask the user a question
Question q = new Question("Really quit?", "yes", "no");
if(q.ask() == "yes")
//quit..And I want to block the execution of the current thread just like we are used to from e.g. windows message boxes.. I know there isnt any code in there to revert to the previous screen yet, i dont know if there is a way to do that easily? Does the Display class keep a history so I can just say hide() or showThePreviousScreenAgain()..
In the debug window of WTK, i can see (via debug println) that the code shows the question, gets to the wait() and bombs with an IllegalMonitorState ; i presume I'm not locking on the same thread that created the lock. I've tried locking on the display, on this (the ui hangs), on the main midlet class.. and none of them work as expected. Can anyone offer any pointers? There is an accessory discussion going on at CodeGuru
Cheers guys!
cjard
Edited by: cjard on Mar 4, 2008 12:37 AM

Hi guys.. I'm posting because I dont know much about the way java ui runs with respect to threading.. Infact, I dont know how many threads a J2ME app would run to write hello world on the screen, or how I would pause them but maintain responsiveness.
I read this thread: SonyEricssonDevelopers
which gave me a few pointers.
I then wrote this code, that doesnt work:
public class QuestionForm extends Form implements CommandListener {
    private static Object lock = new Object();
    private String answer = null;
    private String defaultAnswer = null;
    public QuestionForm(String message, String answer1, String answer2) {
        super("");
        this.defaultAnswer = answer1;
        this.append(new StringItem(message, ""));
        this.addCommand(new Command(answer1, Command.BACK, 1));
        this.addCommand(new Command(answer2, Command.BACK, 2));
        this.setCommandListener(this);
    public String ask(){
        answer = null;
        //static accessor for display
        GoText.display.setCurrent(this);
        synchronized(lock){
            try{
                while(answer == null)
                    wait();
            }catch(Exception ex){
                answer = defaultAnswer;
        return answer;
    public void commandAction(Command c, Displayable d) {
        answer = c.getLabel();
        synchronized(lock){
            notifyAll();
}I want to be able to say:
//some code.. oh we need to ask the user a question
Question q = new Question("Really quit?", "yes", "no");
if(q.ask() == "yes")
//quit..And I want to block the execution of the current thread just like we are used to from e.g. windows message boxes.. I know there isnt any code in there to revert to the previous screen yet, i dont know if there is a way to do that easily? Does the Display class keep a history so I can just say hide() or showThePreviousScreenAgain()..
In the debug window of WTK, i can see (via debug println) that the code shows the question, gets to the wait() and bombs with an IllegalMonitorState ; i presume I'm not locking on the same thread that created the lock. I've tried locking on the display, on this (the ui hangs), on the main midlet class.. and none of them work as expected. Can anyone offer any pointers? There is an accessory discussion going on at CodeGuru
Cheers guys!
cjard
Edited by: cjard on Mar 4, 2008 12:37 AM

Similar Messages

Maybe you are looking for

  • Re: New & Old Domains No Longer Accessible ?

    Problem resolved: When changing directory permissions for whatever reason, make a note of what you changed the permissions from so that you can get them to be what they were originally after you are done with whatever caused you to change the dir per

  • Where can I download missing "Minion Pro" and "Myriad Pro" type fonts?

    For some reason I have fewer Minion Pro & Myriad Pro type fonts on my Windows 7 home computer than I do on my Windows 7 work computer, and I'm trying to do the same commercial project with both of them. I have subscribed to Creative Cloud for over a

  • HDV looks jerky, convert to AIC and exported from FCE: more jerky

    First of all, I am editing a video that was shot in Japan and captured with FCP, hence the footage has the HDV codec. When I view the footage in QT, it looks like the frame rate is messed up (the footage looks jerky, and you can see ghost trail type

  • Selection screen on moudle programming

    The business needs selection parameter for select options to an existing module program. All the functionalities for a select-option in selection screen should be available. I know that we can have normal selection screen 1000 and then call the relav

  • How do you sync notes between ipad and macbook pro

    I have numerous notes on my iPad mini and want to sync it with my MacBook Pro. How?