当前位置: 技术问答>java相关
J2ME Wirteless Toolkit下的又一个问题:(下面的代码为什么调试不能成功?)
来源: 互联网 发布时间:2015-02-18
本文导语: import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class bbb extends MIDlet implements CommandListener { private Display firstDisplay ; private Form firstForm ; private Command doneCommand; public bbb() { firstDi...
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class bbb extends MIDlet implements CommandListener
{
private Display firstDisplay ;
private Form firstForm ;
private Command doneCommand;
public bbb()
{
firstDisplay = Display.getDisplay(this) ;
doneCommand = new Command("DONE", Command.SCREEN, 1);
firstForm = new Form("Hello,测试") ;
StringItem firstStrItem = new StringItem("哈罗","米德列特") ;
firstForm.append(firstStrItem) ;
System.out.println("MIDlet启动") ;
}
protected void startApp() throws MIDletStateChangeException
{
TextBox textBox = new TextBox("Hello Midlet", "Hello !!", 256, 0);
textBox.addCommand(doneCommand);
textBox.setCommandListener( (CommandListener) this);
firstDisplay.setCurrent(firstForm) ;
firstDisplay.setCurrent(textBox);
}
protected void pauseApp()
{
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
{
}
public void commandAction(Command command, Displayable screen)
{
if (command == doneCommand){
destroyApp(false);
notifyDestroyed();
}
}
}
import javax.microedition.midlet.*;
public class bbb extends MIDlet implements CommandListener
{
private Display firstDisplay ;
private Form firstForm ;
private Command doneCommand;
public bbb()
{
firstDisplay = Display.getDisplay(this) ;
doneCommand = new Command("DONE", Command.SCREEN, 1);
firstForm = new Form("Hello,测试") ;
StringItem firstStrItem = new StringItem("哈罗","米德列特") ;
firstForm.append(firstStrItem) ;
System.out.println("MIDlet启动") ;
}
protected void startApp() throws MIDletStateChangeException
{
TextBox textBox = new TextBox("Hello Midlet", "Hello !!", 256, 0);
textBox.addCommand(doneCommand);
textBox.setCommandListener( (CommandListener) this);
firstDisplay.setCurrent(firstForm) ;
firstDisplay.setCurrent(textBox);
}
protected void pauseApp()
{
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
{
}
public void commandAction(Command command, Displayable screen)
{
if (command == doneCommand){
destroyApp(false);
notifyDestroyed();
}
}
}
|
你到底在一开始想显示form还是textbox?
如果是textbox,请注释掉 firstDisplay.setCurrent(firstForm) ;
如果是form,要对form 进行 addcommand和setCommandListener,this 前也不需要加(commandListener),因为this本来就是个commandListener。
如果是textbox,请注释掉 firstDisplay.setCurrent(firstForm) ;
如果是form,要对form 进行 addcommand和setCommandListener,this 前也不需要加(commandListener),因为this本来就是个commandListener。
|
去掉throws MIDletStateChangeException 试试看!
|
或者把startApp pauseApp destroyApp都加上public。