0

hi
i have a j2me application with a display set to Canvas.

when i try to change the midlet's display to another Canvas using
the following command:

Display.getDisplay(this).setCurrent(Canvas2);

nothing happens.

how can i efficiently change a display to another Canvas ?

3
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by peter_budo
0

Hi,

Check this:
http://www.j2ee.me/javame/reference/apis/jsr118/javax/microedition/lcdui/Display.html#setCurrent%28javax.microedition.lcdui.Displayable%29

It says that the setCurrent() call can be delayed.
It also says: "If the application calls setCurrent() while a system screen is active, the effect may be delayed until after the system screen is dismissed.", so try to do:

/* "minimize" */
setCurrent(null);
/* Set new */
setCurrent(canvas);

I haven't tried this myself, so I have no idea if it works nor if this even is a good aproach.

0

i tried it and unfortunately it didn't work, what happened is that i saw both canvases painted in the same form.
i also tried to call repaint() in the first Canvas and paint the whole form in white. it didn't wok.

0

here is my code:

public class MainForm extends MIDlet implements CommandListener {

private Display display = Display.getDisplay(this);
private Command backCommand = new Command ("Back",Command.EXIT,1);    
private Command nextCommand = new Command("Next",Command.OK,1);
     
   public void startApp() {

        startCanvas = new StartCanvas();
        startCanvas.addCommand(backCommand);
        startCanvas.addCommand(nextCommand);
        startCanvas.setCommandListener(this);

        
        menuCanvas = new MenuCanvas();
        menuCanvas.addCommand(backCommand);
        menuCanvas.addCommand(nextCommand);
        menuCanvas.setCommandListener(this);
        
        display.setCurrent(startCanvas);
        
    }


    public void commandAction(Command command, Displayable displayable)
    {
        if (command  ==  backCommand)
        {
            destroyApp(false);
            notifyDestroyed();
        }

        else if (command == nextCommand)
        {
                display.setCurrent(menuCanvas);
        }

}

0

Can you please explain what you trying to do in your startApp() method?
I see you are creating two instances of two classes and then you call first one. However both instances are missing type declaration at start. Secondly from MIDlet you either want to

  • all a class that extends any of Screen sub-classes and call it on MIDlet start
private Display display;

public void startApp(){
    if(display == null){
        display = Display.getDisplay(this);
    }
    display.setCurrent(new StartCanvas(this)); // "this" stands for MIDlet
}
  • or you should declare and initialize inner class and show this directly from MIDlet (most example of internet start like this because they mostly show only one screen)
private Display display;

public void startApp(){
    if(display == null){
        display = Display.getDisplay(this);
    }
    Form form = new Form("My Form");
    
    TextField tf = new TextField("User name", "", 25, TextField.ANY);
    form.append(tf);
    display.setCurrent(form);

Edited by peter_budo: n/a

0

i forgot to copy the declarations of the two Canvases instances, but they exist.
basically what i want to do is change the display from one canvas to another. is that possible ?

0

Start in MIDlet

private Display display;

public void startApp(){
    if(display == null){
        display = Display.getDisplay(this);
    }
    display.setCurrent(new StartCanvas(this)); // "this" stands for MIDlet
}

StartCanvas

public class StartCanvas extends Form implements CommandListener{

    private MyMIDlet midlet;
    private Command nextCanvas;

    public StartCanvas(MyMIDlet _midlet){
        super("Start Canvas");
        midlet = _midlet;
        TextField tf = new TextField("User name", "", 25, TextField.ANY);
        append(tf); 
        nextCanvas = new Command("Next", Command.SCREEN, );
        addCommand(nextCanvas);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d){
        if(c == nextCanvas){
            Display.getDisplay(midle).setCurrent(new MenuCanvas(midlet));
        }
    }

MenuCanvas

public class MenuCanvas extends Form implements CommandListener{

    private MyMIDlet midlet;
    private Command nextCanvas;

    public MenuCanvas(MyMIDlet _midlet){
        super("Menu Canvas"); 
        //REST OF THE CODE
    }
}

Be aware that if you do any heavy computing, networking or local file connection or PIM usage you need to use threads for it and moving from screen to screen more complex

Let me know if there are any errors, I writing this sort "on fly"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.