我在每个表单中使用addSideMenu(this(来添加侧边菜单。菜单项在 ENUM 菜单选项中定义。就我而言,我想在从每个窗体调用另一个窗体之前对控件进行一些处理。如果这是通过窗体上存在的任何按钮或控件发生的,那么我可以进行处理,然后调用下一个窗体。
从侧边菜单调用表单时,我很难做同样的事情。我必须根据表单中存在的元素进行处理,每个表单都有不同的元素。这不能是通用方法。我不明白如果从侧菜单调用另一个表单,我该怎么做同样的事情。请指教。
示例:我在表单"开始"(第一个表单(上,它有按钮"A"和按钮"B"。我从侧面菜单调用表单"设置" ->然后我想在控件移动到设置表单之前访问表单"开始"(第一个表单(的按钮 A 和 B。
侧边菜单代码:
public static void addSideMenu(Form f) {
Toolbar tb = f.getToolbar();
Button logout = new Button("Sign Out");
logout.setUIID("SignoutButton");
for (MenuOptions m : Server.instance.getMenuSortOrder()) {
m.addToSidemenu(tb);
}
tb.addComponentToSideMenu(logout);
}
侧边菜单选项的代码:
public enum MenuOptions {
SCHEDULE("Sch", "Schedule", FontImage.MATERIAL_PERM_CONTACT_CALENDAR,
e -> new AppointmentsForm(false, true, true,
Server.AppointmentFolders.APPOINTMENTS).show()),
ACTIVITY("Start", "Activity", FontImage.MATERIAL_ASSIGNMENT,
e -> new ActivityForm("").show()),
SETTINGS("Settings", "Settings", FontImage.MATERIAL_SETTINGS,
e -> new SettingsForm().show());
}
MenuOptions(String name, String title, char icon,
ActionListener<ActionEvent> al) {
this.name = name;
this.title = title;
this.icon = icon;
this.al = al;
}
public Component createMenuButton() {
Button b = new Button(title);
if (Display.getInstance().isTablet()) {
FontImage.setMaterialIcon(b, icon, 20);
} else {
FontImage.setMaterialIcon(b, icon, 10);
}
Font mediumBoldProportionalFont =
Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
Font.SIZE_MEDIUM);
b.getUnselectedStyle().setFont(mediumBoldProportionalFont);
b.getAllStyles().setBorder(Border.createEtchedRaised());
b.addActionListener(al);
return b;
}
我猜ENUM接受一个动作侦听器。我建议用一个LazyValue<Form>
替换它,这将为您懒惰地创建表单。然后,您可以将操作侦听器实现为:
Form f = lazy.getValue();
doSomethingOnForm(f);
f.show();