1

我使用代号来开发我的移动应用程序。在这个应用程序中,我手动实现了一些类和代码,例如通过硬编码而不是出于某种原因使用代号设计器来创建所有表单。

顺便说一句,我想在类似代号使用的表单中导航,所以我使用了一个Form名为它的类型的变量prevForm,当我想打开一个表单时,我将它设置为当前表单,然后显示新表单。

好的,这是主要场景。在这个应用程序中,我也想实现国际化,所以我为此应用程序创建了自己的哈希表(波斯语和英语)。

这是我的问题:

  1. 如何设置或更改语言并将其应用于我打开的表单?

  2. 我在表单之间导航的方法好吗?

这是我的代码:

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;
}
4

1 回答 1

2

我还在 lwuit 上对我的 UI 进行了硬编码,并且每个类都有一个可变的 parentForm,因此我可以轻松地显示以前的表单。对于语言更改,我知道您可以使用资源编辑器中的本地化。以下是您如何访问它。我想诀窍是如何在代码中的 res 文件中设置 L10N 的内容?另一方面,您可以创建自己的帮助类来反映以下方法。

Resources theme = Resources.open("/theme.res");
theme.getL10N(id, locale);
theme.getL10NResourceNames();
theme.isL10N(name);
theme.listL10NLocales(id)
于 2012-12-05T11:47:48.927 回答