我有两个LWUIT Form
s(主要和更改密码)
一个使用actionPerformed
调用另一个,它的工作原理。
然后,在第二个,我需要得到一些数据,处理并返回到第一个。
要做到这一点,我试图再次使用actionPerformed
。但Ok按钮(手机上的右按钮)不会调用更改密码Form
的actionPerformed
。只需致电主Form
的actionPerformed
即可。为什么?J2ME(LWUIT) - actionPerformed不叫
在代码的其他部分,我也是这样做的,但是MIDlet
和Form
只有一个,它可以工作。
有什么改变?
我失去了很多时间测试代码,但我不能找到解决办法
这是“主” Form
代码:
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;
}
}
}
这是准则更改密码Form
:
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();
}
}
@MarkComix,你能解决这个问题吗? – Vimal 2011-12-27 21:09:27