Hilfe zu Commands

Jonaszinn

Grünschnabel
Hi,
Kann mir vielleicht jemand helfen. Wenn ich das folgenende MIDlet im Emulator starte und dan auf EXIT gehe wird das MIDlet nicht beendet.
Wo habe ich etwas falsch gemacht.


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloWorldMIDlet extends MIDlet
{
private HelloScreen helloScreen=null;
public HelloWorldMIDlet()
{
helloScreen=new HelloScreen(this, "Hello Jonas");
}
public void startApp()
{
Displayable current=Display.getDisplay(this).getCurrent();
if(current==null)
{
Display.getDisplay(this).setCurrent(helloScreen);
}
}
public void pauseApp()
{
}
public void destroyApp(boolean b)
{
}
public void exitRequested()
{
destroyApp(false);
notifyDestroyed();
}
}

class HelloScreen extends TextBox implements CommandListener
{
private HelloWorldMIDlet midlet;
private Command exitCommand;
public HelloScreen(HelloWorldMIDlet midlet, String string)
{
super("HelloWorldMIDlet", string, 256, 0);
this.midlet=midlet;
addCommand(new Command("Beenden", Command.EXIT, 1));
addCommand(new Command("Hauptmenu", Command.BACK, 1));
setCommandListener(this);
}
public void commandAction(Command command, Displayable displayable)
{
switch(command.getCommandType())
{
case Command.BACK:
break;
case Command.EXIT:
break;
}
}
}
 
Ich habe das MIDlet jetzt geändert, indem ich midlet.exitRequested(); eingefügt habe. Doch was füge ich jetzt beim 2. Command ein



import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloWorldMIDlet extends MIDlet
{
private HelloScreen helloScreen=null;
public HelloWorldMIDlet()
{
helloScreen=new HelloScreen(this, "Hello Jonas");
}
public void startApp()
{
Displayable current=Display.getDisplay(this).getCurrent();
if(current==null)
{
Display.getDisplay(this).setCurrent(helloScreen);
}
}
public void pauseApp()
{
}
public void destroyApp(boolean b)
{
}
public void exitRequested()
{
destroyApp(false);
notifyDestroyed();
}
}

class HelloScreen extends TextBox implements CommandListener
{
private HelloWorldMIDlet midlet;
private Command exitCommand;
public HelloScreen(HelloWorldMIDlet midlet, String string)
{
super("HelloWorldMIDlet", string, 256, 0);
this.midlet=midlet;
addCommand(new Command("Beenden", Command.EXIT, 1));
addCommand(new Command("Zurück", Command.BACK, 1));
setCommandListener(this);
}
public void commandAction(Command command, Displayable displayable)
{
switch(command.getCommandType())
{
case Command.BACK:
break;

case Command.EXIT:
midlet.exitRequested();
}
}
}
 
Zurück