【发布时间】:2011-10-28 10:55:53
【问题描述】:
我是 GWT 的新手,所以请帮助我。我的GWT MenuBar 有一个关于如何getSelectedItem() 的问题。
这是我的代码:
public class Menu extends Composite implements Command {
private MenuBar menu = new MenuBar();
private MenuBar priceMgt = new MenuBar( true );
private MenuBar salesReport = new MenuBar( true );
// and a lot more menubars
private String[] itemPriceMgt = {
"Manage Price List", "Print Product Pricing", "Price Proof List"
};
private String[] itemSalesReport = {
"Sales Transaction List", "Cashier Report", "Media Tender Report",
"Sales Report by Employee", "Sales Warranty Tracking", "Sales Report by Product",
"Sales Summary by Branch", "Sales Summary by Product", "Sales Summary by Period",
"Product Movement Analysis", "Sales Comparison",
"Sales Book", "Download eSales"
};
public Menu() {
loadMenu();
}
private void loadMenu() {
addSubMenuItem( priceMgt, itemPriceMgt );
addSubMenuItem( salesReport, itemSalesReport );
menu.addItem( "Home", false, this );
menu.addItem( "Price Management", priceMgt );
menu.addItem( "Sales Report", salesReport );
menu.addItem( "Logout", false, this );
initWidget( menu );
}
private void addSubMenuItem( MenuBar menubar, String[] list ) {
for( int i = 0; i < list.length; i++ ) {
menubar.addItem( list[i], this );
}
}
public void execute() {
// load the selected module
// by getting the selected item
// i can't use menu.getSelectedItem() - it's protected.
// when i extend this class to MenuBar, adding Item says ambiguous
// method addItem(String,Command) for MenuBar
// how can I get the items being selected/clicked?
}
}
其他人可能会说这是一个没有用的帖子,但我真的不知道如何弄清楚。请帮我。提前致谢。
【问题讨论】: