如何简单创建Menu(菜单)

MenuMain为主程序,MenuMainScreen是对我们程序界面的设置。

下面我们来看一下代码:

MenuMain:

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;


public class MenuMain extends UiApplication {
	public static void main(String[] args) {
		
		new MenuMain().enterEventDispatcher();
	}
	private MenuMain() 
    {
		MainScreen Menu = new MenuMainScreen();    
        Menu.setTitle( new LabelField("Dillon<Menu Demo>", LabelField.USE_ALL_WIDTH | LabelField.ELLIPSIS ));
        pushScreen( Menu );
    }
}

 MenuMainScreen:

import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;

public class MenuMainScreen extends MainScreen {
	private MenuItem _addItem = new AddItem();
	 
protected void makeMenu( Menu menu, int instance ) 
{
    super.makeMenu( menu, instance );

    menu.add( _addItem );  
}   
}
final class AddItem extends MenuItem
{
    AddItem() 
    {
        super("Add" , 100, 100 );
    }
	public void run() {
		Dialog.alert("Failure");
	}        
}
 

你可能感兴趣的:(UI,.net)