接下来我们看界面类,它们通常包括控制器类、界面的Item还有一些Command。
public NewPhoneUI(UIController uicontroller)
{
super(Title.add_record);
this.uicontroller = uicontroller;
nameField = new TextField(Title.name, null, 25, TextField.ANY);
mobileField = new TextField(Title.mobile, null, 25,
TextField.PHONENUMBER);
choice = new ChoiceGroup(Title.choice, ChoiceGroup.MULTIPLE);
phoneField = new TextField(Title.phone, null, 25, TextField.PHONENUMBER);
emailField = new TextField(Title.email, null, 25, TextField.EMAILADDR);
choice.append(Title.detail, null);
this.append(nameField);
this.append(mobileField);
this.append(choice);
this.addCommand(saveCommand);
this.addCommand(backCommand);
this.setCommandListener(this);
this.setItemStateListener(this);
}
通常他们把控制器类作为参数传递给构造器,并在构造器内部注册监听器,绘制界面等。它们通过commandAction()方法来传递事件编号给控制器类去处理,例如
public void commandAction(Command arg0, Displayable arg1)
{
if (arg0 == backCommand)
{
uicontroller
.handleEvent(UIController.EventID.EVENT_NEWPHONE_BACK_MAINUI);
}
}这样就基本上完成了导航问题,扩展起来非常容易,添加一个界面类,然后在控制器类中初始化并添加适当的事件编号就可以了。