如何使用getSelecteditem方法

时间:2012-11-03 10:12:37

标签: gwt

如何对菜单栏对象使用getSelecteditem方法?

我的代码在这里:

    final MenuBar f2=new MenuBar(true);

    Command cm=new Command(){
    @Override
    public void execute() {
        // TODO Auto-generated method stub
        Window.alert("hello");
    }
};
f2.addItem(prop.getProperty("Submenu1"),cm);
f2.addItem(prop.getProperty("Submenu2"),cm);

2 个答案:

答案 0 :(得分:1)

MenuBar menuList = new MenuBar(true);
menuList.setAutoOpen(true);

/**
 * First Menu Item
 */
MenuItem firstMenu = new MenuItem("First Menu", new Command() {
    @Override
    public void execute() {
       // write code for First Menu Click.
           doForFirstMenu();
    }
});
menuList.addItem(firstMenu );


/**
 * For Second Menu Item
 */
MenuItem secondMenu= new MenuItem("Second Menu", new Command() {
    @Override
    public void execute() {
       // Write code for second menu click.
       doForSecondMenu();
    }
});
menuList.addItem(secondMenu);

答案 1 :(得分:0)

为每个MenuItem添加一个单独的命令!

final MenuBar f2 = new MenuBar(true);

Command cm = new Command() {
    @Override
    public void execute() {
    Window.alert("sub1");
    }
};
Command cm2 = new Command() {
    @Override
    public void execute() {
    Window.alert("sub2");
    }
};

f2.addItem("Submenu1", cm);
f2.addItem("Submenu2", cm2);