×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    Exit-command disappearing

    Hello,

    I´m having problems with exit-command disappearing from a Canvas when adding a command to it. Here´s an example midlet:

    Code:
    package command;
    
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.midlet.MIDlet;
    
    public class CommandMidlet extends MIDlet implements CommandListener
    {
        private Command exitCommand = new Command("Exit",Command.EXIT, 0);
        
        private Canvas view = new CommandCanvas();
        
        
        public void startApp()
        {
            view.setCommandListener(this);
            view.addCommand(exitCommand);
            Display.getDisplay(this).setCurrent(view);
    
        }
    
        public void destroyApp(boolean b)
        {
        }
    
        public void pauseApp()
        {
        }
    
        public void commandAction(Command c, Displayable d) {
            if(c == exitCommand) {
                notifyDestroyed();
            }
    
        }
        private class CommandCanvas extends Canvas implements CommandListener {
    
            private CommandListener listener = null;
            
            private Command addCommand = new Command("Add command",Command.SCREEN,1);
            
            private Command addedCommand = new Command("Added command",Command.SCREEN,2);
            
            private Command fullScreenCommand = new Command("Toggle fullscreen",Command.SCREEN, 0);
            private boolean fullscreen = true;
            
            public CommandCanvas() {
                setFullScreenMode(fullscreen);
                super.setCommandListener(this);
                addCommand(addCommand);
                addCommand(fullScreenCommand);
            }
            
            protected void paint(Graphics g) {
                g.drawString("Select command", 0, 0, Graphics.TOP|Graphics.LEFT);
            }
    
            public void commandAction(Command c, Displayable d) {
              if(c == addCommand) {
                  addCommand(addedCommand);
              }
              else if(c == fullScreenCommand) {
                  fullscreen = !fullscreen;
                  setFullScreenMode(fullscreen);
              }
              else if(listener != null) {
                  listener.commandAction(c, this);
              }
            }
            
            public void setCommandListener(CommandListener l) {
                listener = l;
            }
    
        }
    }
    When the "Add command" is selected "Exit" disappears from the menu. But if you change the canvas back to normal mode the exit is in the right softkey.

    Using some other Command type than EXIT or BACK or handling all the commands in the canvas class works. This happens in S60 3rd edition emulator and S60 3rd edition phones but not in S60 3rd editon FP1 simulator.

    Any ideas why this is happening?

  2. #2
    Registered User
    Join Date
    Jul 2006
    Posts
    41

    Re: Exit-command disappearing

    Honestly, your code's architecture is so bad that it is normal it des not work. Let me explain.

    You set a commandListener to your canvas (the canvas itself) in its constructor then in startApp, you set another CommandListener...(the MIDlet).

    All should be done in the same class, the Canvas one. Adding command, handling commands, ... should be done in the canvas class. If it does not fit you well, then you can manage all this from the class that creates the canvas. But do everything IN THE SAME CLASS.

    Hope it helps.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    Re: Exit-command disappearing

    Yes, I know that it is not the conventional way of handling commands in MIDP. But as you can see, my CommandCanvas-class overrides the setCommandListener and the actual setCommandListener-method in the Canvas-class is called only in the constructor (super.setCommandListener). That way the system always calls the commandAction-method in the CommandCanvas class. The CommandCanvas handles the commands it is responsible of and forwards all the other commands to the external CommandListener.

    The point of this is that my canvas class can adds it´s own commands that are used to manipulate the canvas itself but whatever external class that is using the canvas to add it´s commands for changing to another Displayable, exit the application etc.

    The architecture is working, the problem is that if the commands added by the external listener is of the BACK or EXIT type it is not displayed in the menu of a canvas in fullscreen mode after a command is added. And it happens only on S60 3rd Edition emulator or device.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    3

    Re: Exit-command disappearing

    I can confirm the same behaviour with S60 3rd Edition FP1. The command mapped to the right soft key is not available if the canvas is in full screen mode... If you have more exit commands then only the one which is mapped to the right soft key will disappear from the commands if you switch to full screen mode. I think it is a device problem.

Similar Threads

  1. why my does not exit on N73 when i push exit soft key?
    By byronlilu in forum Mobile Java General
    Replies: 2
    Last Post: 2007-06-28, 21:29
  2. Removing default exit button
    By jmdeveloper in forum Mobile Java General
    Replies: 9
    Last Post: 2006-11-07, 16:30
  3. Exit question...
    By GeKI in forum Symbian
    Replies: 0
    Last Post: 2006-07-06, 15:56
  4. N70 Reset bug
    By sebboB in forum General Development Questions
    Replies: 2
    Last Post: 2005-12-28, 23:09
  5. UNDESIRED Exit command key.
    By tektronic in forum Mobile Java General
    Replies: 4
    Last Post: 2005-05-13, 18:27

Posting Permissions

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