本文整理汇总了Java中java.awt.Menu类的典型用法代码示例。如果您正苦于以下问题:Java Menu类的具体用法?Java Menu怎么用?Java Menu使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Menu类属于java.awt包,在下文中一共展示了Menu类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initProjectMenu
import java.awt.Menu; //导入依赖的package包/类
private static Menu initProjectMenu() {
Menu mnProject = new Menu(Resources.get("menu_project"));
CheckboxMenuItem compress = new CheckboxMenuItem(Resources.get("menu_compressProjectFile"));
compress.setState(userPreferences.isCompressFile());
compress.addItemListener(e -> userPreferences.setCompressFile(compress.getState()));
CheckboxMenuItem sync = new CheckboxMenuItem(Resources.get("menu_syncMaps"));
sync.setState(userPreferences.isSyncMaps());
sync.addItemListener(e -> userPreferences.setSyncMaps(sync.getState()));
MenuItem importSpriteFile = new MenuItem(Resources.get("menu_assets_importSpriteFile"));
importSpriteFile.addActionListener(a -> EditorScreen.instance().importSpriteFile());
MenuItem importSprite = new MenuItem(Resources.get("menu_assets_importSprite"));
importSprite.addActionListener(a -> EditorScreen.instance().importSprites());
mnProject.add(importSprite);
mnProject.add(importSpriteFile);
mnProject.addSeparator();
mnProject.add(compress);
mnProject.add(sync);
return mnProject;
}
示例2: addMenu
import java.awt.Menu; //导入依赖的package包/类
void addMenu(MenuBar b, String name, String[] items) {
/* It's a very poor design to encapsulate menu creation this way.
* Can't customize the menus this way (e.g. shortcut keys,
* mnemonics, disabling, etc. */
Menu menu = new Menu(name);
if (name.equals("Tools") && !TT_AVAILABLE) {
// Terrible place to do this. Forced to due to method design.
menu.setEnabled(false);
}
addMenuItems(menu, items);
b.add(menu);
}
示例3: addMenuItems
import java.awt.Menu; //导入依赖的package包/类
void addMenuItems(Menu f, String[] m) {
for (int i = 0; i < m.length; i++) {
MenuItem item = new MenuItem(m[i].substring(1));
char c = m[i].charAt(0);
if (c != '-') {
item.setShortcut(new MenuShortcut(c));
}
item.addActionListener(this);
f.add(item);
}
}
示例4: addMenu
import java.awt.Menu; //导入依赖的package包/类
/**
* Method declaration
*
*
* @param b
* @param name
* @param items
*/
void addMenu(MenuBar b, String name, String[] items) {
/* It's a very poor design to encapsulate menu creation this way.
* Can't customize the menus this way (e.g. shortcut keys,
* mnemonics, disabling, etc. */
Menu menu = new Menu(name);
if (name.equals("Tools") && !TT_AVAILABLE) {
// Terrible place to do this. Forced to due to method design.
menu.setEnabled(false);
}
addMenuItems(menu, items);
b.add(menu);
}
示例5: test3
import java.awt.Menu; //导入依赖的package包/类
private static void test3(final MenuBar menuBar) {
final Menu helpMenu1 = new Menu("Help Menu1");
final Menu helpMenu2 = new Menu("Help Menu2");
menuBar.setHelpMenu(helpMenu1);
checkCurrentMenu(menuBar, helpMenu1);
checkMenuCount(menuBar, 1);
checkHelpMenu(helpMenu1, true);
checkHelpMenu(helpMenu2, false);
menuBar.setHelpMenu(helpMenu2);
checkCurrentMenu(menuBar, helpMenu2);
checkMenuCount(menuBar, 1);
checkHelpMenu(helpMenu1, false);
checkHelpMenu(helpMenu2, true);
menuBar.remove(helpMenu2);
checkCurrentMenu(menuBar, null);
checkMenuCount(menuBar, 0);
checkHelpMenu(helpMenu1, false);
checkHelpMenu(helpMenu2, false);
}
示例6: addHelpMenu
import java.awt.Menu; //导入依赖的package包/类
/**
* Adds a help menu to this MenuBar. Gnome styleguides say the help
* menu is just the last item in the menubar (they are NOT right
* justified).
*/
public void addHelpMenu (Menu menu)
{
if (hasHelpMenu)
{
// Remove the (help) menu, which is after all the other items.
delMenu(((MenuBar) awtWidget).getMenuCount());
hasHelpMenu = false;
}
if (menu != null)
{
addMenu(menu);
hasHelpMenu = true;
}
}
示例7: handleMouseEvent
import java.awt.Menu; //导入依赖的package包/类
/**
* Handles mouse events.
*
* @param ev the mouse event
*/
public void handleMouseEvent(MouseEvent ev)
{
Point point = ev.getPoint();
for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
{
Menu menu = awtMenuBar.getMenu(i);
SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer();
int x1 = peer.getX();
int x2 = x1 + peer.getWidth();
if (point.x >= x1 && point.x <= x2)
{
ev.translatePoint(peer.getX(), peer.getY());
peer.handleMouseEvent(ev);
break;
}
}
}
示例8: handleMouseMotionEvent
import java.awt.Menu; //导入依赖的package包/类
/**
* Handles mouse motion events.
*
* @param ev the mouse motion event
*/
public void handleMouseMotionEvent(MouseEvent ev)
{
Point point = ev.getPoint();
for (int i = 0; i < awtMenuBar.getMenuCount(); i++)
{
Menu menu = awtMenuBar.getMenu(i);
SwingMenuPeer peer = (SwingMenuPeer) menu.getPeer();
int x1 = peer.getX();
int x2 = x1 + peer.getWidth();
if (point.x >= x1 && point.x <= x2)
{
ev.translatePoint(peer.getX(), peer.getY());
peer.handleMouseMotionEvent(ev);
break;
}
}
}
示例9: generateMenuItem
import java.awt.Menu; //导入依赖的package包/类
private static MenuItem generateMenuItem(TreeElement element) {
if(element.isLeaf()) {
MenuItem item = new MenuItem(element.getCaption());
item.addActionListener(new MasterFrameMenu(element.getFullID()));
if(element.isHidden()) {
item.setEnabled(false);
} else if(!element.getEnabled()) {
item.setEnabled(false);
}
items.put(element.getFullID(), item);
return(item);
} else {
Menu menu = new Menu(element.getCaption());
Iterator<TreeElement> i = element.getChilds();
while(i.hasNext()) {
menu.add(generateMenuItem(i.next()));
}
if(element.isHidden()) {
menu.setEnabled(false);
}
items.put(element.getFullID(), menu);
return(menu);
}
}
示例10: addMenuItems
import java.awt.Menu; //导入依赖的package包/类
/**
* Method declaration
*
*
* @param f
* @param m
*/
private void addMenuItems(Menu f, String[] m) {
for (int i = 0; i < m.length; i++) {
if (m[i].equals("-")) {
f.addSeparator();
} else {
MenuItem item = new MenuItem(m[i]);
item.addActionListener(this);
f.add(item);
}
}
}
示例11: main
import java.awt.Menu; //导入依赖的package包/类
public static void main(String[] args) {
Container container = new Container();
Panel panel = new Panel();
Menu menu = new Menu(); //!!! its not component
TextField textField = new TextField();
container.add(textField);
Window win = new Window(null);
win.pack();
menu.setShortcut(new MenuShortcut(12));
new MenuItem("label", new MenuShortcut(33, true));
Menu file = new Menu("File");
MenuItem print;
file.add(print = new MenuItem("Print", new MenuShortcut('p')));
}
示例12: createPopupMenu
import java.awt.Menu; //导入依赖的package包/类
protected static PopupMenu createPopupMenu() {
final PopupMenu popup = new PopupMenu();
MenuItem aboutItem = new MenuItem("About");
CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
Menu displayMenu = new Menu("Display");
MenuItem errorItem = new MenuItem("Error");
MenuItem warningItem = new MenuItem("Warning");
MenuItem infoItem = new MenuItem("Info");
MenuItem noneItem = new MenuItem("None");
MenuItem exitItem = new MenuItem("Exit");
// Add components to pop-up menu
popup.add(aboutItem);
popup.addSeparator();
popup.add(cb1);
popup.add(cb2);
popup.addSeparator();
popup.add(displayMenu);
displayMenu.add(errorItem);
displayMenu.add(warningItem);
displayMenu.add(infoItem);
displayMenu.add(noneItem);
popup.add(exitItem);
return popup;
}
示例13: OpenPartnerFrame
import java.awt.Menu; //导入依赖的package包/类
public OpenPartnerFrame (Go go)
{
super(Global.resourceString("Open_Partners"));
G = go;
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu m = new MyMenu(Global.resourceString("Options"));
m.add(new MenuItemAction(this, Global.resourceString("Close")));
mb.add(m);
setLayout(new BorderLayout());
L = new java.awt.List();
L.setFont(Global.SansSerif);
refresh();
add("Center", L);
JPanel bp = new MyPanel();
bp.add(new ButtonAction(this, Global.resourceString("Connect")));
bp.add(new ButtonAction(this, Global.resourceString("Refresh")));
bp.add(new MyLabel(" "));
bp.add(new ButtonAction(this, Global.resourceString("Close")));
add("South", bp);
Global.setwindow(this, "openpartner", 300, 200);
seticon("ijago.gif");
setVisible(true);
OPFU = new OpenPartnerFrameUpdate(this);
}
示例14: initFileMenu
import java.awt.Menu; //导入依赖的package包/类
private static Menu initFileMenu() {
Menu mnFile = new Menu(Resources.get("menu_file"));
MenuItem create = new MenuItem(Resources.get("menu_createProject"));
create.setShortcut(new MenuShortcut(KeyEvent.VK_N));
create.addActionListener(a -> EditorScreen.instance().create());
MenuItem load = new MenuItem(Resources.get("menu_loadProject"));
load.setShortcut(new MenuShortcut(KeyEvent.VK_O));
load.addActionListener(a -> EditorScreen.instance().load());
MenuItem save = new MenuItem(Resources.get("menu_save"));
save.setShortcut(new MenuShortcut(KeyEvent.VK_S));
save.addActionListener(a -> EditorScreen.instance().save(false));
MenuItem saveAs = new MenuItem(Resources.get("menu_saveAs"));
saveAs.addActionListener(a -> EditorScreen.instance().save(true));
MenuItem exit = new MenuItem(Resources.get("menu_exit"));
exit.setShortcut(new MenuShortcut(KeyEvent.VK_Q));
exit.addActionListener(a -> Game.terminate());
mnFile.add(load);
mnFile.add(create);
mnFile.add(save);
mnFile.add(saveAs);
mnFile.addSeparator();
recentFiles = new Menu(Resources.get("menu_recentFiles"));
loadRecentFiles();
mnFile.add(recentFiles);
mnFile.addSeparator();
mnFile.add(exit);
return mnFile;
}