}
public void destroyApp(boolean unconditional)
{
}
public void pauseApp()
{
display.setCurrent(null);
props = null;
}
}
在上面的程序(CMD.java)中定义了八个命令。如果commandAction()方法接到这八个命令,多半是调用showScreen()方法,将这几个命令输出。showScreen()方法会产生一个新的容器对象(Form),作为当前的屏幕,并把截获的命令显示在屏幕中。
CMD.java的运行效果如下2图所示(当屏幕出现Hello World字样的时候,你需要按下退出键,命令菜单就会出现了,你可以依次执行各个命令)。
TextBox文本框对象
发信站: 北大未名站 (2001年10月20日20:36:34 星期六) , 站内信件
TextBox是一个容器类型的对象(和Form的性质一样)。用法如下所示:
package fancy.test;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ShowTextBox extends MIDlet implements CommandListener
{
private Display display;
private TextBox txtBox;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
public ShowTextBox()
{
display = Display.getDisplay(this);
}
public void startApp()
{
//or :
//String str="hello world";
//txtBox = new TextBox("Text Box",str,str.length(),0);
//the follow code is wrong:
//txtBox = new TextBox("Text Box",str,any number here,0);
txtBox = new TextBox("Text Box",null,200,0);
txtBox.addCommand(exitCommand);
txtBox.setCommandListener(this);
display.setCurrent(txtBox);
}
public void commandAction(Command c, Displayable s)
{
if (c == exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
public void destroyApp(boolean unconditional)
{
}