×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    15

    Problem With Exit Command On GameCanvas

    Can anyone help me? When I try to add an exitCommand to my GameCanvas, I always seem to get an extra 'Close' option and both commands seem to be called by both softkeys.

    I have written a game using the GameCanvas, which I am running fullscreen.

    I need to add an exit command so that the game can be closed.

    So I did this


    Code:
    GameCanvas game = new GameCanvas(true);
    Command exitCommand = new Command("Exit",Command.EXIT,0);
    game.addCommand(exitCommand);
    game.setCommandListener(this);
    game.setFullScreenMode(true);
    getDisplay().setCurrent(game);
    The problem is, weird stuff happens. First of all, when I press the softkey, I get TWO options - EXIT and CLOSE which do the same thing. But I only added one command? It seems like the CLOSE command is a default, but if I don't add the exit command, nothing happens at all when softkeys are pressed.

    Also, these options both appear if EITHER softkey is pressed, not just one softkey.

    Can anyone tell me what I am doing wrong? I just want ONE exit command on one softkey.

    Any advice would be greatly appreciated. Thanks

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Problem With Exit Command On GameCanvas

    hi,

    are you authoring/testing on Nokia Series 60 device (with OS prior to S60 3rdED FP1)?
    http://discussion.forum.nokia.com/fo...highlight=exit

    regards,
    Peter

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    15

    Re: Problem With Exit Command On GameCanvas

    I am testing on Nokia 6680 so I think so, yes.

    Does that post mean this is not a problem on newer phones? Is there a workaround for the older phones?

  4. #4
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Problem With Exit Command On GameCanvas

    hi,

    I'm not experienced yet but for me it seems that we cannot suspend "Exit" command invoked by AMS when user choose "Exit" added by system,

    here is sample code:
    Code:
    package tests;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class MidletExitApp extends MIDlet implements CommandListener {
        public void startApp() {
            Displayable current = Display.getDisplay(this).getCurrent();
            if(current == null){
                current = (Displayable)new MyCanvas();
                current.addCommand(new Command("Quit", Command.EXIT, 1));
                current.setCommandListener(this);
            }
            Display.getDisplay(this).setCurrent(current);
        }
        
        public void pauseApp() {
        }
        
        public void destroyApp(boolean unconditional) throws MIDletStateChangeException {
            if(unconditional == true){
                if(canQuit == true){
                    System.out.println("destroyed by user");
                } else {
                    //  thats is called by AMS after using
                    //  default "EXIT" command added by system
                    System.out.println("destroyed by AMS");
                }
            }else{
                /// only if "unconditional == false "
                //  midlet can suspend quit
                throw new MIDletStateChangeException();
            }
        }
        
        public void commandAction(Command command, Displayable displayable) {
            if(command.getCommandType() == Command.EXIT){
                System.out.println("EXIT");
                canQuit = true;
                Display.getDisplay(this).setCurrent(null);
                notifyDestroyed();
            }
        }
        private boolean canQuit = false;
        
        class MyCanvas extends Canvas{
            
            public MyCanvas(){
                super();
            }
            protected void paint(Graphics g) {
                g.setColor(0xFFFFFF);
                g.drawRect(0, 0, getWidth(), getHeight());
            }
            
        }
    }
    AMS calls destroyApp(...) with unconditional == true, so that's not possible to throw exception here and enforce application to be not closed,

    yes, that's not a problem on newer S60 series devices, there is no "Exit" default command added,

    regards,
    Peter

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    15

    Re: Problem With Exit Command On GameCanvas

    Thanks Peter. I'm not very experienced in J2ME either - been learning it for about 2 weeks. It seems very fragmented and buggy though. I think I might go back to Flash! :)

  6. #6
    Registered User
    Join Date
    Jul 2006
    Posts
    15

    Re: Problem With Exit Command On GameCanvas

    i dont fine problem if u hanle the exit with commandAction and call destroyApp() of the main MIDlet.

    okey man..

  7. #7
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Problem With Exit Command On GameCanvas

    hi mrtipale,

    the main problem with "Exit' command added on S60 (with except of new 3rd Ed) is that is not handled by commandAction listener (posted code simplify checking command type, but Command.EXIT is not called by system),
    so we can only for example try to save game state in "destroyApp" handler if executed by AMS, so next time game is started we could try to provide "continue" feature,

    regards,
    Peter

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    6

    Re: Problem With Exit Command On GameCanvas

    My personal problem with the Exit command being added is that it looks unprofessional.
    For example, I was working on a BreakOut style game. I needed only a single command: Close

    So, I added it.
    And I end up with two commands: Close and Exit.
    So I take out the Close. The Exit disappears too.
    I can't see a way to have just a single command there.
    I don't mind using their Exit command. What I've taken to doing in other projects is adding in several commands, and having my Close function at the top, and letting them add their Exit to the end, so it's less noticeable.

    But I still don't know what to do when Close is the only command I want to add...

  9. #9
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Problem With Exit Command On GameCanvas

    hi bladestorm,

    if we are talking about S60 2nd Ed FP2 (or generally all S60 before 3rd Ed) that you can do following for games (canvas/game canvas/nokia full screen canvas):
    Code:
    package tests;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class TestMidlet extends MIDlet implements CommandListener {
        public void startApp() {
            Displayable current = Display.getDisplay(this).getCurrent();
            if(current == null){
                current = (Displayable)new MyCanvas(this);
                ((MyCanvas)current).setFullScreenMode(true);
            }
            Display.getDisplay(this).setCurrent(current);
        }
        
        public void pauseApp() {
        }
        
        public void destroyApp(boolean unconditional) {
        }
        
        public void commandAction(Command command, Displayable displayable) {
            if(command.getCommandType() == Command.EXIT){
                Display.getDisplay(this).setCurrent(null);
                notifyDestroyed();
            }
        }
        //
        class MyCanvas extends Canvas {
            private TestMidlet parent;
            public MyCanvas(final TestMidlet parent){
                this.parent = parent;
            }
            protected void paint(Graphics g) {
                g.setColor(0xFFFFFF);
                g.fillRect(0,0,getWidth(), getHeight());
                String quitLabel = "Quit";
                Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
                int labelWidth = font.stringWidth(quitLabel);
                int labelHeight = font.getHeight();
                g.setColor(0x00);
                g.drawString("Quit", getWidth()- labelWidth, getHeight()-labelHeight, Graphics.LEFT | Graphics.TOP);
            }
            protected void keyPressed(int keyCode){
                switch(keyCode){
                    //
                    // RIGHT SOFT KEY
                    //
                    case -7:
                        parent.commandAction(new Command("Quit", Command.EXIT, 1), this);
                        break;
                    default:
                        // nothing //
                }
            }
        }
    }
    that is:
    - put screen into full screen mode
    - add manually drawn "Quit" label
    - on RightSoftKey pressed do quit

    hth,
    regards,
    Peter
    Last edited by peterblazejewicz; 2006-08-20 at 23:01.

  10. #10
    Registered User
    Join Date
    Aug 2006
    Posts
    6

    Re: Problem With Exit Command On GameCanvas

    Oh my, I didn't know you could use the soft keys directly!
    Is that common to most midp java implementations? Or just symbian?
    (not that it really matters. point is, this'll be much better next time I'm designing a program!)

    Thanks a lot. :)

  11. #11
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Problem With Exit Command On GameCanvas

    hi,

    thats for full canvas, so for MIPD 2.0 only Canvas/Game Canvas,
    for nokia Devices with MIDP 1.0 FullScreen from nokia.ui.* package,
    full canvas because "Quit" is simpy drawn and no high-level command is added,

    note: however that pointless because main topic was how S60 (Symbian OS) prior to 3rd edition (or 2nd Edition Feature Pack 3 if I'm not wrong) implements high-level menus,

    hth,
    regards,
    peter

Similar Threads

  1. Replies: 1
    Last Post: 2005-12-04, 12:01
  2. S_60 a problem with exit app.
    By gadkii in forum Mobile Java General
    Replies: 3
    Last Post: 2004-06-13, 08:08
  3. Replies: 1
    Last Post: 2004-06-03, 05:58
  4. 7210 Silent Problem
    By MarkMckim in forum Mobile Java General
    Replies: 1
    Last Post: 2003-03-18, 12:36
  5. PJava runtime problem within Nokia 9210, Hrlp~!
    By Nokia_Archive in forum PersonalJava
    Replies: 1
    Last Post: 2002-05-28, 13:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×