关于J2ME中菜单合并的问题!
我是J2ME初学者。写了一个HelloWorld,可是在Command菜单合并的时候遇到了问题!代码如下:importjavax.microedition.lcdui.*...
我是J2ME初学者。写了一个Hello World,可是在Command菜单合并的时候遇到了问题!代码如下:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class HelloWorld extends MIDlet implements CommandListener {
private Command exitCommand;
private Command delete1Command;
private Command delete2Command;
private TextBox tb;
public HelloWorld() {
exitCommand = new Command("Exit", Command.EXIT, 1);
delete1Command = new Command("Delete1",Command.BACK , 1);
delete2Command = new Command("Delete2", Command.BACK , 1);
tb = new TextBox("Hello MIDlet", "Hello,World!", 12, 0);
tb.addCommand(delete1Command);
tb.addCommand(delete2Command);
tb.addCommand(exitCommand);
tb.setCommandListener(this);
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(tb);
System.out.println("startApp");
}
protected void pauseApp() {
System.out.println("pauseApp");
}
protected void destroyApp(boolean c) throws MIDletStateChangeException {
System.out.println("destroyApp");
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
try {
destroyApp(false);
} catch (MIDletStateChangeException exception) {
System.out.println("MIDletStateChangeException");
}
notifyDestroyed();
}
else if (c == delete1Command)
{
tb.delete(tb.size()-1,1);
}
else if (c == delete2Command)
{
tb.delete(0, 1);
}
}
}
我想把“Delete1”和“Delete2”这两个命令合并放在左边的菜单里面,“Exit”单独放在右边的菜单里面,可是运行结果总是像我图片里面显示的这样。该怎么修改呢?谢谢各位了! 展开
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class HelloWorld extends MIDlet implements CommandListener {
private Command exitCommand;
private Command delete1Command;
private Command delete2Command;
private TextBox tb;
public HelloWorld() {
exitCommand = new Command("Exit", Command.EXIT, 1);
delete1Command = new Command("Delete1",Command.BACK , 1);
delete2Command = new Command("Delete2", Command.BACK , 1);
tb = new TextBox("Hello MIDlet", "Hello,World!", 12, 0);
tb.addCommand(delete1Command);
tb.addCommand(delete2Command);
tb.addCommand(exitCommand);
tb.setCommandListener(this);
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(tb);
System.out.println("startApp");
}
protected void pauseApp() {
System.out.println("pauseApp");
}
protected void destroyApp(boolean c) throws MIDletStateChangeException {
System.out.println("destroyApp");
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
try {
destroyApp(false);
} catch (MIDletStateChangeException exception) {
System.out.println("MIDletStateChangeException");
}
notifyDestroyed();
}
else if (c == delete1Command)
{
tb.delete(tb.size()-1,1);
}
else if (c == delete2Command)
{
tb.delete(0, 1);
}
}
}
我想把“Delete1”和“Delete2”这两个命令合并放在左边的菜单里面,“Exit”单独放在右边的菜单里面,可是运行结果总是像我图片里面显示的这样。该怎么修改呢?谢谢各位了! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询