public void startApp() {
t = new TextBox("Hello", "Hello, World!", 256, 0);
t.addCommand(exitCommand);
t.addCommand(view);
t.setCommandListener(this);
MyCanvas m=new MyCanvas();
m.addCommand(exitCommand);
m.addCommand(view);
m.setCommandListener(this);
if (System.getProperty(
"microedition.io.file.FileConnection.version") != null)
t.setTicker(new Ticker(System.getProperty(
"microedition.io.file.FileConnection.version")));
else
t.setTicker(new Ticker("no"));
display.setCurrent(m);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (c==view && s = m)
{
display.setCurrent(t);
}
}
}
以上代码中,主类实现了Commandlistener接口,所有屏幕的command都由这个类负责监听和处理。那么相当于由这个主类来决定如何切换屏幕.
就这么简单。