MainMidlet.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MainMidlet extends MIDlet implements CommandListener
{
private Display display;
private Form form = new Form("Wellcome!!");
private Command okCommand = new Command("OK",Command.OK,1);//选择OK,换到下一个屏幕
private Form ns ;
private StringItem si = new StringItem("First Screen","~_~");
public MainMidlet()
{
form.addCommand(okCommand);
form.append(si);
}
public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(form);
form.setCommandListener(this);
}
public void pauseApp()
{
}
public void destroyApp(boolean b)
{
}
public void commandAction(Command c,Displayable s)
{
if(c==okCommand)
{
ns = new NextScreen(display,form);//最关键的地方在这里:)
display.setCurrent(ns);
}
}
}
NextScreen.java
import javax.microedition.lcdui.*;
public class NextScreen extends Form implements CommandListener
{
private Display display;
private Displayable parent;
private Command backCommand = new Command("BACK",Command.BACK,1);
private StringItem si = new StringItem("SecondScrean","~_~");
public NextScreen(Display d,Displayable p)
{
super("nextscreen");//使得NextScreen可以直接调中其父类Form中的函数
display = d;
parent = p;
append(si);
addCommand(backCommand);
setCommandListener(this);
}
public void commandAction(Command c,Displayable s)
{
if(c==backCommand)
{
display.setCurrent(parent);
}
}
}