You Are Here:

Community: Developer Discussion Boards

#1 Old Problem With Exit Command On GameCanvas - 2006-07-31, 18:14

Join Date: Jul 2006
Posts: 15
tobyw_1969
Offline
Registered User
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
Reply With Quote

#2 Old Re: Problem With Exit Command On GameCanvas - 2006-07-31, 18:23

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
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
Reply With Quote

#3 Old Re: Problem With Exit Command On GameCanvas - 2006-08-01, 12:07

Join Date: Jul 2006
Posts: 15
tobyw_1969
Offline
Registered User
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?
Reply With Quote

#4 Old Re: Problem With Exit Command On GameCanvas - 2006-08-01, 15:36

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
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
Reply With Quote

#5 Old Re: Problem With Exit Command On GameCanvas - 2006-08-02, 00:16

Join Date: Jul 2006
Posts: 15
tobyw_1969
Offline
Registered User
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! :)
Reply With Quote

#6 Old Re: Problem With Exit Command On GameCanvas - 2006-08-18, 07:57

Join Date: Jul 2006
Posts: 15
mrtipale
Offline
Registered User
i dont fine problem if u hanle the exit with commandAction and call destroyApp() of the main MIDlet.

okey man..
Reply With Quote

#7 Old Re: Problem With Exit Command On GameCanvas - 2006-08-18, 23:02

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
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
Reply With Quote

#8 Old Re: Problem With Exit Command On GameCanvas - 2006-08-19, 17:39

Join Date: Aug 2006
Posts: 6
bladestorm
Offline
Registered User
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...
Reply With Quote

#9 Old Re: Problem With Exit Command On GameCanvas - 2006-08-20, 23:51

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
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-21 at 00:01.
Reply With Quote

#10 Old Re: Problem With Exit Command On GameCanvas - 2006-08-23, 05:09

Join Date: Aug 2006
Posts: 6
bladestorm
Offline
Registered User
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. :)
Reply With Quote

#11 Old Re: Problem With Exit Command On GameCanvas - 2006-08-24, 01:28

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
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
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Why ALL series 60 have same problem, when default ringtone rings instead of custom as LinuxHata Audio 1 2005-12-04 13:01
S_60 a problem with exit app. gadkii Mobile Java General 3 2004-06-13 09:08
6600 Embedded exit problem with firmware 4.09.1 turnburs General Symbian C++ 1 2004-06-03 06:58
7210 Silent Problem MarkMckim Mobile Java General 1 2003-03-18 13:36
PJava runtime problem within Nokia 9210, Hrlp~! Nokia_Archive PersonalJava 1 2002-05-28 14:15

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d127641X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZgamesQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ