| Reply | « Previous Thread | Next Thread » |
|
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);
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 |
| tobyw_1969 |
| View Public Profile |
| Find all posts by tobyw_1969 |
|
Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
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 |
| peterblazejewicz |
| View Public Profile |
| Find all posts by peterblazejewicz |
|
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? |
| tobyw_1969 |
| View Public Profile |
| Find all posts by tobyw_1969 |
|
Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
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());
}
}
}
yes, that's not a problem on newer S60 series devices, there is no "Exit" default command added, regards, Peter |
| peterblazejewicz |
| View Public Profile |
| Find all posts by peterblazejewicz |
|
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! :)
|
| tobyw_1969 |
| View Public Profile |
| Find all posts by tobyw_1969 |
|
i dont fine problem if u hanle the exit with commandAction and call destroyApp() of the main MIDlet.
okey man.. |
|
Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
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 |
| peterblazejewicz |
| View Public Profile |
| Find all posts by peterblazejewicz |
|
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... |
| bladestorm |
| View Public Profile |
| Find all posts by bladestorm |
|
Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
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 //
}
}
}
}
- 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.
|
| peterblazejewicz |
| View Public Profile |
| Find all posts by peterblazejewicz |
|
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. :) |
| bladestorm |
| View Public Profile |
| Find all posts by bladestorm |
|
Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
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 |
| peterblazejewicz |
| View Public Profile |
| Find all posts by peterblazejewicz |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |