11 Replies Latest reply: Sep 30, 2010 9:56 PM by DarrylBurke RSS

    Switch between midlet and Canvas

    800537
      hi.
      i have a midlet (commandlistener) and a canvas(extends canvas). i create a list in startApp,when user choose her selection i will show canvas.

      mycanvas.setFullScreenMode(true);
      display.setCurrent(mycanvas);
      ---------------------------------------

      then, when user press any key i need to show midlet (back to first)


      i used this codes but did not work:

      midlet mymidlet;


      mymidlet.startApp();

      OR:

      mymidlet.display.getdisplay(mymidlet).setcurrnet(mylist);

      and similar...

      what do i do?


      sorry for my poor English.
        • 1. Re: Switch between midlet and Canvas
          DarrylBurke
          797534 wrote:
          then, when user press any key i need to show midlet (back to first)
          A MIDlet is not a Displayable, so it can't be shown. You have already demonstrated that you know how to set a Displayable as current. Do that again, passing as parameter the Deployable you want to show.

          Some other notes:
          1. Read the notifications on the forum before you post. They are there for a purpose.
          2. Use correct capitalization for the first word in a sentence, proper nouns, the first person singular I, and Java class and member names.
          3. To get better help sooner, post a SSCCE -- a Short, Self Contained, Compilable and Executable, Example Program -- http://mindprod.com/jgloss/sscce.html

          db
          • 2. Re: Switch between midlet and Canvas
            800537
            Ok
            I tested it again ,My IDE is Netbeans 6.8, Simulator shows these messages:


            TRACE: <at java.lang.NullPointerException: 0>, Exception caught in Display class
            java.lang.NullPointerException: 0

            and canvas is working correctly(It seems that do nothing.)


            Can you paste some code?
            • 3. Re: Switch between midlet and Canvas
              800537
              I search INTERNET and everybody tell "use a display methods" and similar sentences.
              I do something wrong.real device and emulator work fine,when i need to show first list emulator shows null pointer error .
              Whats wrong?

              another question:
              how to close my program when canvas is running? (similar that upper question with different concept)


              best regards.
              • 4. Re: Switch between midlet and Canvas
                Opal
                Add an EXIT command to the canvas and handle the event.
                • 5. Re: Switch between midlet and Canvas
                  762917
                  Msba:

                  Can you put your midlet and canvas code to see what you are trying to do, and what the problem could be.
                  • 6. Re: Switch between midlet and Canvas
                    800537
                    this is some parts of my midlet :


                    public class LF extends MIDlet implements CommandListener{
                    Display display;
                    Command ok,Exit;
                    Canvas fullmap;


                    public void startApp() {
                    display=Display.getDisplay(this);
                    Exit=new Command(string.cmd_exit,Command.EXIT,1);
                    ok=new Command(string.cmd_ok,Command.OK,4);
                    fullmap=new gcanvas();
                    .
                    .
                    .
                    .
                    .
                    }
                    public void destroyApp(boolean unconditional) {
                    notifyDestroyed();
                    }
                    public void commandAction(Command c,Displayable d) {

                    if(c.equals(Exit) ||(l1.isSelected(4)&& c.equals(ok))) destroyApp(true);
                    if(c.equals(ok)&&l1.isSelected(0)){
                    fullmap.setFullScreenMode(true);
                    display.setCurrent(fullmap);} //show the canvas.
                    }



                    my canvas:

                    public class gcanvas extends Canvas implements CommandListener {
                    LF main;
                    public gcanvas() {
                    try {
                         setCommandListener(this);
                         addCommand(new Command("Exit", Command.EXIT, 1));

                    } catch(Exception e) {
                    e.printStackTrace();
                    }
                    }
                    public void paint(Graphics g) {

                    try{
                    ax=Image.createImage(addr);g.drawImage(ax, X, Y,g.LEFT|g.TOP);
                    .
                    .
                    .
                    .
                    .
                    }
                    .
                    .
                    .
                    .
                    public void commandAction(Command command, Displayable displayable) {
                    if(command.getLabel().equalsIgnoreCase("exit")){
                    try{
                    main.display.getDisplay(main).setCurrent(main.l1);//l1 is my list(menu)
                    }
                    catch(Exception E){
                    System.out.println("Sad");
                    }
                    }
                    }


                    commandAction is wrong in my canvas,this: "main.display.getDisplay(main).setCurrent(main.l1);"

                    1- How to show my midlet after my canvas was showed?
                    2-how to exit form Canvas ? (such as DestroyApp(true) )
                    • 7. Re: Switch between midlet and Canvas
                      DarrylBurke
                      Msba wrote:
                      1- How to show my midlet after my canvas was showed?
                      What didn't you understand about my earlier response? Or are you determined to continue to ask the wring question?
                      Darryl Burke wrote:
                      A MIDlet is not a Displayable, so it can't be shown.
                      db
                      • 8. Re: Switch between midlet and Canvas
                        800537
                        Sorry,sorry,sorry

                        I completely understand your post and earlier post.


                        I have a list in my midlet.I want to show it after a canvas.Are you understand my goal? my last post (code program shows it)
                        Thanks a lot for your attention.You are very helpful.
                        ----------------
                        Can you help me about that,I write default code but not work .just it.

                        Sorry,sorry,sorry
                        • 9. Re: Switch between midlet and Canvas
                          800537
                          I understand my answer at last.(after search INTERNET and test many program)

                          before show the Canvas we must write:
                          MyCanvas.setCommandListener(this) and
                          MyCanvas.addCommand(Exit);

                          in midlet,then display it.we complete commandAction in midlet (no in canvas) Indeed,It is my answer.


                          thanks all Member ,Specially for Darryl Burke.
                          • 10. Re: Switch between midlet and Canvas
                            800537
                            My last post described the answer.
                            • 11. Re: Switch between midlet and Canvas
                              DarrylBurke
                              Msba wrote:
                              thanks all Member ,Specially for Darryl Burke.
                              You're welcome, but your thanks would be better expressed by taking my advice.
                              Darryl Burke wrote:
                              1. Read the notifications on the forum before you post. They are there for a purpose.
                              db