我使用代号来开发我的移动应用程序。在这个应用程序中,我手动实现了一些类和代码,例如通过硬编码而不是出于某种原因使用代号设计器来创建所有表单。
顺便说一句,我想在类似代号使用的表单中导航,所以我使用了一个Form
名为它的类型的变量prevForm
,当我想打开一个表单时,我将它设置为当前表单,然后显示新表单。
好的,这是主要场景。在这个应用程序中,我也想实现国际化,所以我为此应用程序创建了自己的哈希表(波斯语和英语)。
这是我的问题:
如何设置或更改语言并将其应用于我打开的表单?
我在表单之间导航的方法好吗?
这是我的代码:
public class BaseForm extends Form implements ActionListener {
public BaseForm(){
this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
}
Command exit, ok, back;
Form prevForm;
protected void initForm(){
}
protected void showForm(){
}
protected void showForm(final Form prevForm){
//String name = this.getName();
//if("Reminder".equals(name) || "3Transaction".equals(name))
{
this.prevForm = prevForm;
Form f = this;
back = new Command("Back");
//ok = new Command("Ok");
//delete = new Command("Delete");;
Button button = new Button("Button");
f.addCommand(back);
//f.addCommand(ok);
//f.addCommand(delete);
//f.addComponent(button);
f.addCommandListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (ae.getCommand().equals(back)) {
//Do Exit command code
System.out.println("Back pressed");
prevForm.showBack();
} else if (ae.getCommand().equals(ok)) {
//Do Start command code
System.out.println("Ok pressed");
}
}
});
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
//Do button code
System.out.println("Action performed");
}
});
}
showForm();
}}
对于打开的嵌套表单,我使用以下代码:
LanguageUI lang = new LanguageUI();
lang.showForm(this);
更改语言[表格]:
protected boolean onBtnSave() {
if(isRbFarsiSelected()){
UIManager.getInstance().setResourceBundle(new CommonSettings().getFarsi());
}
else {
UIManager.getInstance().setResourceBundle(new CommonSettings().getEnglish());
}
return false;
}