Java me J2ME(LWiit)-未调用actionPerformed

Java me J2ME(LWiit)-未调用actionPerformed,java-me,lwuit,Java Me,Lwuit,我有两个Lwiit表单s(主密码和更改密码) 一个使用actionPerformed调用另一个,它就工作了。 然后,在第二个示例中,我需要获取一些数据,进行处理并返回到第一个示例。 为此,我尝试再次使用actionPerformed。但Ok按钮(手机上的右键)不会调用更改密码表单的操作执行。只需调用主表单的actionPerformed。为什么? 在代码的其他部分,我也这样做,但是使用MIDlet,并且只有一个表单,它就可以工作了 有什么需要改变的吗? 我在测试代码时浪费了很多时间,但我找不到解

我有两个Lwiit
表单
s(主密码和更改密码)
一个使用
actionPerformed
调用另一个,它就工作了。
然后,在第二个示例中,我需要获取一些数据,进行处理并返回到第一个示例。
为此,我尝试再次使用
actionPerformed
。但Ok按钮(手机上的右键)不会调用更改密码表单的
操作执行
。只需调用主
表单的
actionPerformed
。为什么?

在代码的其他部分,我也这样做,但是使用
MIDlet
,并且只有一个
表单
,它就可以工作了

有什么需要改变的吗?
我在测试代码时浪费了很多时间,但我找不到解决方案

这是“Main”表单的代码:

public class InfoView extends Form implements ActionListener{

    private Command backCommand;
    private Command changePasswordCommand;
    private Command okChangePasswordForm;

     private ChangePassword changePasswordForm;

    public InfoView(Command backC){

        super();

        this.addCommand(backC);
        this.setBackCommand(backC);

        this.setScrollableY(true);

        this.setTitle(LanguageManager.getText("RootTitle"));

        changePasswordCommand = new Command(LanguageManager.getText("ChangePassword"), Constants.CHANGE_PASSWORD_COMMAND);

        okChangePasswordForm = new Command(LanguageManager.getText("Ok"), Constants.OK_CHANGE_PASSWORD_COMMAND);

        this.addAllCommands();       

        this.initForm();
    }

    public void initForm(){

        Style s = this.getStyle();

        s.setMargin(0, 0, 0, 0);
        s.setPadding(0, 0, 0, 0);

        this.addCommandListener(this);

        backCommand = new Command(LanguageManager.getText("Back"), Constants.BACK_COMMAND);

    }

    private void addAllCommands(){

        this.addCommand(changePasswordCommand);

        this.addCommand(changeContactInfoCommand);
    }

    public void actionPerformed(ActionEvent arg0) {

        //Obtengo la Opción seleccionada
        Command cmd = arg0.getCommand();

        if (cmd == null) {
            return;
        }

        System.out.println(String.valueOf(cmd.getId()));

        switch (cmd.getId()) {

            case Constants.CHANGE_PASSWORD_COMMAND:

                System.out.println("CHANGE_PASSWORD_COMMAND");

                //this.setGlassPane(null);

                if (changePasswordForm == null) {
                    changePasswordForm = new ChangePassword();
                    changePasswordForm.addCommand(backCommand);
                    changePasswordForm.addCommand(okChangePasswordForm);
                    changePasswordForm.addCommandListener(this);
                    changePasswordForm.setBackCommand(backCommand);
                }

                changePasswordForm.show();
                arg0.consume();
                break;

            case Constants.BACK_COMMAND:

                System.out.println("BACK_COMMAND");

                //20111004 MB: Cuando vuelvo, desincronizo para que al 
                //cambiar de tarjeta funcione
                //protocolManager.deSync();

                addAllCommands();

                this.show();

                this.editInfoForm = null;
                this.changePasswordForm = null;

                System.gc();

                break; 

            case Constants.OK_CHANGE_PASSWORD_COMMAND:

                System.out.println("OK_CHANGE_PASSWORD_COMMAND");

                this.editInfoForm = null;

                this.show();

                System.gc();

                break;                
        }
    }
}
import com.sun.lwuit.Form;
import com.sun.lwuit.*;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import Project.language.LanguageManager;

public class ChangePassword extends Form implements ActionListener {

    private TextField oldPassword;
    private TextField newPassword;
    private TextField repeatNewPassword;

    public ChangePassword(){

        super ();

        this.setTitle(LanguageManager.getText("ChangePasswordTitle"));

        addCommandListener(this);

        this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        this.addComponent(new Label(LanguageManager.getText("Actual")));

        oldPassword = new TextField("");
        oldPassword.setConstraint(TextArea.PASSWORD);

        this.addComponent(oldPassword);

        this.addComponent(new Label(LanguageManager.getText("New")));

        newPassword = new TextField("");
        newPassword.setConstraint(TextArea.PASSWORD);

        this.addComponent(newPassword);

        this.addComponent(new Label(LanguageManager.getText("Repeat")));

        repeatNewPassword = new TextField("");
        repeatNewPassword.setConstraint(TextArea.PASSWORD);

        this.addComponent(repeatNewPassword);
    }

    private String getOldPass(){
        return this.oldPassword.getText();
    }

    private String getNewPass(){
        return this.newPassword.getText();
    }

    public void actionPerformed(ActionEvent arg0) {

        Command cmd = arg0.getCommand();

        String oldPasswordVar = getOldPass();
        String newPasswordVar = getNewPass();

    }

}
这是更改密码的代码表单

public class InfoView extends Form implements ActionListener{

    private Command backCommand;
    private Command changePasswordCommand;
    private Command okChangePasswordForm;

     private ChangePassword changePasswordForm;

    public InfoView(Command backC){

        super();

        this.addCommand(backC);
        this.setBackCommand(backC);

        this.setScrollableY(true);

        this.setTitle(LanguageManager.getText("RootTitle"));

        changePasswordCommand = new Command(LanguageManager.getText("ChangePassword"), Constants.CHANGE_PASSWORD_COMMAND);

        okChangePasswordForm = new Command(LanguageManager.getText("Ok"), Constants.OK_CHANGE_PASSWORD_COMMAND);

        this.addAllCommands();       

        this.initForm();
    }

    public void initForm(){

        Style s = this.getStyle();

        s.setMargin(0, 0, 0, 0);
        s.setPadding(0, 0, 0, 0);

        this.addCommandListener(this);

        backCommand = new Command(LanguageManager.getText("Back"), Constants.BACK_COMMAND);

    }

    private void addAllCommands(){

        this.addCommand(changePasswordCommand);

        this.addCommand(changeContactInfoCommand);
    }

    public void actionPerformed(ActionEvent arg0) {

        //Obtengo la Opción seleccionada
        Command cmd = arg0.getCommand();

        if (cmd == null) {
            return;
        }

        System.out.println(String.valueOf(cmd.getId()));

        switch (cmd.getId()) {

            case Constants.CHANGE_PASSWORD_COMMAND:

                System.out.println("CHANGE_PASSWORD_COMMAND");

                //this.setGlassPane(null);

                if (changePasswordForm == null) {
                    changePasswordForm = new ChangePassword();
                    changePasswordForm.addCommand(backCommand);
                    changePasswordForm.addCommand(okChangePasswordForm);
                    changePasswordForm.addCommandListener(this);
                    changePasswordForm.setBackCommand(backCommand);
                }

                changePasswordForm.show();
                arg0.consume();
                break;

            case Constants.BACK_COMMAND:

                System.out.println("BACK_COMMAND");

                //20111004 MB: Cuando vuelvo, desincronizo para que al 
                //cambiar de tarjeta funcione
                //protocolManager.deSync();

                addAllCommands();

                this.show();

                this.editInfoForm = null;
                this.changePasswordForm = null;

                System.gc();

                break; 

            case Constants.OK_CHANGE_PASSWORD_COMMAND:

                System.out.println("OK_CHANGE_PASSWORD_COMMAND");

                this.editInfoForm = null;

                this.show();

                System.gc();

                break;                
        }
    }
}
import com.sun.lwuit.Form;
import com.sun.lwuit.*;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import Project.language.LanguageManager;

public class ChangePassword extends Form implements ActionListener {

    private TextField oldPassword;
    private TextField newPassword;
    private TextField repeatNewPassword;

    public ChangePassword(){

        super ();

        this.setTitle(LanguageManager.getText("ChangePasswordTitle"));

        addCommandListener(this);

        this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        this.addComponent(new Label(LanguageManager.getText("Actual")));

        oldPassword = new TextField("");
        oldPassword.setConstraint(TextArea.PASSWORD);

        this.addComponent(oldPassword);

        this.addComponent(new Label(LanguageManager.getText("New")));

        newPassword = new TextField("");
        newPassword.setConstraint(TextArea.PASSWORD);

        this.addComponent(newPassword);

        this.addComponent(new Label(LanguageManager.getText("Repeat")));

        repeatNewPassword = new TextField("");
        repeatNewPassword.setConstraint(TextArea.PASSWORD);

        this.addComponent(repeatNewPassword);
    }

    private String getOldPass(){
        return this.oldPassword.getText();
    }

    private String getNewPass(){
        return this.newPassword.getText();
    }

    public void actionPerformed(ActionEvent arg0) {

        Command cmd = arg0.getCommand();

        String oldPasswordVar = getOldPass();
        String newPasswordVar = getNewPass();

    }

}

明白了

InfoView.actionPerformed(…)
中,在
Constants.CHANGE\u PASSWORD\u命令下:
ChangePassword()
构造函数中,
ChangePassword.addCommandListener(…)
changePasswordForm.addCommandListener(此)重写因此,当显示
ChangePassword
表单时,
InfoView.actionPerformed(…)
的按键事件处于活动状态

代码片段#1

...
case Constants.CHANGE_PASSWORD_COMMAND:
    changePasswordForm = new ChangePassword();
    changePasswordForm.addCommand(backCommand);
    changePasswordForm.addCommandListener(this); //<-- PROBLEM, because 'this' 
                                                 //          is referring to
                                                 //          'InfoView' and NOT
                                                 //          'ChangePassword'
    changePasswordForm.setBackCommand(backCommand);
...
。。。
case Constants.CHANGE_PASSWORD_命令:
changePasswordForm=新的ChangePassword();
changePasswordForm.addCommand(backCommand);
changePasswordForm.addCommandListener(此)//