Command command = new Command() {
public void execute() {
Window.alert("Click");
}
};
MenuBar menu = new MenuBar();
MenuBar file = new MenuBar(true);
MenuBar edit = new MenuBar(true);
MenuBar view = new MenuBar(true);
menu.addItem("File", file);
MenuItem editItem = (MenuItem)menu.addItem("Edit", edit);
menu.addItem("View", view);
item = (MenuItem)menu.addItem("Help", command);
item.setEnabled(false);
file.addItem("Open", command);
file.addItem("Close", command);
file.addItem("Save", command);
file.addItem("Exit", command);
edit.addItem("Undo", command);
edit.addItem("Redo", command);
edit.addItem("Cut", command);
edit.addItem("Copy", command);
edit.addItem("Paste", command);
editItem.setEnabled(false); // Disable after adding children so they get disabled too
view.addItem("Date", true, command, MenuItem.Type.CHECK, false);
view.addItem("Time", true, command, MenuItem.Type.CHECK, true);
view.addSeparator();
view.addItem("Radio 1", true, command, MenuItem.Type.RADIO, false);
view.addItem("Radio 2", true, command, MenuItem.Type.RADIO, true);
view.addSeparator();
view.addItem("Radio 3", command, MenuItem.Type.RADIO, false, 1);
view.addItem("Radio 4", command, MenuItem.Type.RADIO, true, 1);
view.addSeparator();
view.addItem("Description", command, MenuItem.Type.CHECK, false);
view.addItem("Quantity", command, MenuItem.Type.CHECK, true);
view.addSeparator();
item = (MenuItem)view.addItem("Disabled", (Command)command, MenuItem.Type.INDENT);
item.setEnabled(false);
item = (MenuItem)view.addItem("Enabled", (Command)command, MenuItem.Type.INDENT);
item.setEnabled(false);
item.setEnabled(true);
root.add(menu);
}