To convert from AWT to AFC, instances of java.awt.PopupMenu should be transformed into instances of com.ms.ui.UIMenuList.
PopupMenu extends Menu: be sure to see its changes.
AWT's PopupMenus (which are made up of MenuItems) place a menu on a specified part of a component. In AFC, you build a menu using UIMenuList, create a UIContextMenu containing that, and then place it on the screen using a special feature of UIContextMenus. UIContextMenus are meant to work as right-click type menus in a component: however, you can also launch them into a specific location. So code that used to look like
Component myComponent = new
Component();
PopupMenu myPopMenu = new PopupMenu();
myPopMenu.add(new MenuItem("First Item"));
myPopMenu.show(myComponent, 10, 10);
will now look like
UIComponent myComponent =
new UIComponent();
UIMenuList myMenuList = new UIMenuList();
myMenuList.add(new UIText("First Item"));
UIContextMenu myPopMenu = new UIContextMenu(myMenuList);
myPopMenu.launchAt(10, 10, myComponent);
AFC also provides you many more options for your menus: you can add any UIComponent to a UIMenuList (like a UIItem, which combines text and images, or any kind of button) and provide many other kinds of menu types.
This is the set of changes you need to make to port all PopupMenu methods to UIMenuList/UIContextMenu methods. Any method not listed here or below does not need to be changed.
AWT Code | AFC Code | Comments |
PopupMenu() or PopupMenu(String) |
UIMenuList() | UIMenuLists cannot be associated with names: you need to assign a UIMenuButton or UIMenuItem to the UIMenuList to do that. |
show(Component, int, int) | menu =
UIContextMenu(UIMenuList); menu.launchAt(int, int, Component); |
See the usage example above for a clearer demonstration. |