当前位置: 技术问答>java相关
望指点迷津
来源: 互联网 发布时间:2015-11-15
本文导语: 我写了以下程序,运行后选择Test1或Test2后按与EXI对应的键无法退出,望高人指点 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ListEventMIDlet extends MIDlet implements CommandListener { private Command exitCom...
我写了以下程序,运行后选择Test1或Test2后按与EXI对应的键无法退出,望高人指点
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ListEventMIDlet extends MIDlet implements CommandListener
{
private Command exitCommand;
private Command exitCommand2;
private Display display;
public ListEventMIDlet()
{
display = Display.getDisplay(this);
exitCommand = new Command("Exit",Command.EXIT,1);
exitCommand2 = new Command("Exit",Command.EXIT,1);
}
public void startApp()
{
List l = new List("Test Iten",Choice.IMPLICIT);
l.setCommandListener(this);
l.append("Test 1",null);
l.append("Test 2",null);
l.addCommand(exitCommand);
display.setCurrent(l);
}
public void pauseApp()
{
}
public void destroyApp(boolean unditional)
{
}
public void commandAction(Command c,Displayable s)
{
if (c == exitCommand)
{
notifyDestroyed();
} else
{
List tmp = (List) s;
switch(tmp.getSelectedIndex())
{
case 0:
TextBox t1= new TextBox("Test1","Test1",256,0);
t1.addCommand(exitCommand2);
display.setCurrent(t1);
break;
case 1:
TextBox t2 = new TextBox("Test2","Test2",256,0);
t2.addCommand(exitCommand2);
display.setCurrent(t2);
break;
}
}
}
}
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ListEventMIDlet extends MIDlet implements CommandListener
{
private Command exitCommand;
private Command exitCommand2;
private Display display;
public ListEventMIDlet()
{
display = Display.getDisplay(this);
exitCommand = new Command("Exit",Command.EXIT,1);
exitCommand2 = new Command("Exit",Command.EXIT,1);
}
public void startApp()
{
List l = new List("Test Iten",Choice.IMPLICIT);
l.setCommandListener(this);
l.append("Test 1",null);
l.append("Test 2",null);
l.addCommand(exitCommand);
display.setCurrent(l);
}
public void pauseApp()
{
}
public void destroyApp(boolean unditional)
{
}
public void commandAction(Command c,Displayable s)
{
if (c == exitCommand)
{
notifyDestroyed();
} else
{
List tmp = (List) s;
switch(tmp.getSelectedIndex())
{
case 0:
TextBox t1= new TextBox("Test1","Test1",256,0);
t1.addCommand(exitCommand2);
display.setCurrent(t1);
break;
case 1:
TextBox t2 = new TextBox("Test2","Test2",256,0);
t2.addCommand(exitCommand2);
display.setCurrent(t2);
break;
}
}
}
}
|
你这样写代码吧
public void quitApp()
{
destroyApp(true);
notifyDestroyed();
}
public void commandAction(Command c,Displayable s)
{
if (c == exitCommand)
{
quitApp();
} else
public void quitApp()
{
destroyApp(true);
notifyDestroyed();
}
public void commandAction(Command c,Displayable s)
{
if (c == exitCommand)
{
quitApp();
} else
|
在你的程序中虽然
notifyDestroyed();
但你没有触发
destroyApp();
而destroyApp();是Midlet必要的方法,结束Midlet
notifyDestroyed();
但你没有触发
destroyApp();
而destroyApp();是Midlet必要的方法,结束Midlet
|
少了exitCommand.setCommandListener(this);
可以结贴了
可以结贴了
|
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ListEventMIDlet extends MIDlet implements CommandListener
{
private Command exitCommand;
private Command exitCommand2;
private Display display;
public ListEventMIDlet()
{
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT,1);//加在这里
exitCommand = new Command("Exit",Command.EXIT,1);
exitCommand2 = new Command("Exit",Command.EXIT,1);
}
public void startApp()
{
List l = new List("Test Iten",Choice.IMPLICIT);
l.setCommandListener(this);
l.append("Test 1",null);
l.append("Test 2",null);
l.addCommand(exitCommand);
display.setCurrent(l);
}
public void pauseApp()
{
}
public void destroyApp(boolean unditional)
{
}
public void commandAction(Command c,Displayable s)
{
if (c == exitCommand)
{
notifyDestroyed();
} else
{
List tmp = (List) s;
switch(tmp.getSelectedIndex())
{
case 0:
TextBox t1= new TextBox("Test1","Test1",256,0);
t1.addCommand(exitCommand2);
display.setCurrent(t1);
break;
case 1:
TextBox t2 = new TextBox("Test2","Test2",256,0);
t2.addCommand(exitCommand2);
display.setCurrent(t2);
break;
}
}
}
}
import javax.microedition.lcdui.*;
public class ListEventMIDlet extends MIDlet implements CommandListener
{
private Command exitCommand;
private Command exitCommand2;
private Display display;
public ListEventMIDlet()
{
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT,1);//加在这里
exitCommand = new Command("Exit",Command.EXIT,1);
exitCommand2 = new Command("Exit",Command.EXIT,1);
}
public void startApp()
{
List l = new List("Test Iten",Choice.IMPLICIT);
l.setCommandListener(this);
l.append("Test 1",null);
l.append("Test 2",null);
l.addCommand(exitCommand);
display.setCurrent(l);
}
public void pauseApp()
{
}
public void destroyApp(boolean unditional)
{
}
public void commandAction(Command c,Displayable s)
{
if (c == exitCommand)
{
notifyDestroyed();
} else
{
List tmp = (List) s;
switch(tmp.getSelectedIndex())
{
case 0:
TextBox t1= new TextBox("Test1","Test1",256,0);
t1.addCommand(exitCommand2);
display.setCurrent(t1);
break;
case 1:
TextBox t2 = new TextBox("Test2","Test2",256,0);
t2.addCommand(exitCommand2);
display.setCurrent(t2);
break;
}
}
}
}