Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a class that extends GameCanvas,
in the class i want when user press the pause command it replace with resume command
how can i do it?
Posted

1 solution

Easy (I do it all the time). Create two (almost identical) commands
Java
static final Command pauseCommand = new Command("Pause", Command.ITEM, 1);
static final Command resumeCommand = new Command("Resume", Command.ITEM, 1);


In your startup code, add only the pause command to your displayable (canvas, form or whatever).

In your commandAction routine, have something like this:
Java
public void commandAction(Command cmd, Displayable disp) {
    if (cmd.equals(pauseCommand)) {
        disp.removeCommand(pauseCommand);
        disp.addCommand(resumeCommand);
        // whatever you do to pause
    } else if (cmd.equals(resumeCommand)) {
        disp.removeCommand(resumeCommand);
        disp.addCommand(pauseCommand);
        // whatever you do to resume
    }
}

Note that if you are really pausing the midlet, a resume command inside it won't be very useful!

Peter
[edit] fixed typo in cut'n'pasted code. [/edit]
 
Share this answer
 
v2
Comments
Reza Oruji 12-Aug-11 14:08pm    
thank you for your help
if it's not useful how can i do pause and resume in a game?
Peter_in_2780 12-Aug-11 17:53pm    
I'm just pointing out that if your midlet really enters a paused state, then it no longer has access to the display screen, so your resume command is not available. The user has to do something else (external) to resume the midlet, and how he does that depends very much on the platform. Read the documentation on javax.microedition.midlet, particularly around pauseApp() and notifyPaused().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900