日期:2014-05-20  浏览次数:20721 次

初学,J2ME切换页面总是
我新建了一个类,继承Form,
然后在主页面类中
InputData   input=new   InputData( "item ");
if(mainList.getSelectedIndex()==0)
{
    display.setCurrent(input);
}
用这个来换到新的界面,可是要怎么返回原来的界面啊?
if(command.getCommandType()==Command.CANCEL)
{
      consume   parent=new   consume();
        parent.display.setCurrent(parent.mainList);
                   
}
这样不行啊,要怎么做才能返回第一界面啊?

------解决方案--------------------
你重新的new一个对象是不行的,直接使用原来new出来的对象就好了
------解决方案--------------------
给第2个窗体类中的构造函数 传递1个参数
EXAMPLE:
主窗体
Class A extends Form{
Form B;
Display display;
``
A(){
``
B=new B(this,display);
``
}
}
子窗体
ClsssB extends Form{
Form A;
B(Form A,Display display){
``
this.A=A;
``
}

void comandAction(```){
//返回按纽里面写成下面的
if(command.getCommandType()==Command.CANCEL){
display.setCurrnet(A);
}

}