我有兩個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