当前位置: 首页>>代码示例>>Java>>正文


Java MenuItem.addActionListener方法代码示例

本文整理汇总了Java中java.awt.MenuItem.addActionListener方法的典型用法代码示例。如果您正苦于以下问题:Java MenuItem.addActionListener方法的具体用法?Java MenuItem.addActionListener怎么用?Java MenuItem.addActionListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.MenuItem的用法示例。


在下文中一共展示了MenuItem.addActionListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addToRecent

import java.awt.MenuItem; //导入方法依赖的package包/类
private void addToRecent(String s) {

        for (int i = 0; i < iMaxRecent; i++) {
            if (s.equals(sRecent[i])) {
                return;
            }
        }

        if (sRecent[iRecent] != null) {
            mRecent.remove(iRecent);
        }

        sRecent[iRecent] = s;

        if (s.length() > 43) {
            s = s.substring(0, 40) + "...";
        }

        MenuItem item = new MenuItem(s);

        item.setActionCommand("#" + iRecent);
        item.addActionListener(this);
        mRecent.insert(item, iRecent);

        iRecent = (iRecent + 1) % iMaxRecent;
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:DatabaseManager.java

示例2: initProjectMenu

import java.awt.MenuItem; //导入方法依赖的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;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:26,代码来源:Program.java

示例3: initSystemTray

import java.awt.MenuItem; //导入方法依赖的package包/类
private static void initSystemTray() {
  // add system tray icon with popup menu
  if (SystemTray.isSupported()) {
    SystemTray tray = SystemTray.getSystemTray();
    PopupMenu menu = new PopupMenu();
    MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
    exitItem.addActionListener(a -> Game.terminate());
    menu.add(exitItem);

    trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
    trayIcon.setImageAutoSize(true);
    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:19,代码来源:Program.java

示例4: createPopupMenu

import java.awt.MenuItem; //导入方法依赖的package包/类
private PopupMenu createPopupMenu(final TrayIcon trayIcon,
        final int menuCount) {

    final PopupMenu trayIconPopupMenu = new PopupMenu();

    for (int i = 1; i <= menuCount; ++i) {
        final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i);

        popupMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent ae) {
                trayIcon.setPopupMenu(createPopupMenu(trayIcon,
                        menuCount + 1));
            }
        });

        trayIconPopupMenu.add(popupMenuItem);
    }

    return trayIconPopupMenu;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:UpdatePopupMenu.java

示例5: generateMenuItem

import java.awt.MenuItem; //导入方法依赖的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);
    }
}
 
开发者ID:Martin-Dames,项目名称:Tingeltangel,代码行数:25,代码来源:MasterFrameMenu.java

示例6: addMenuItems

import java.awt.MenuItem; //导入方法依赖的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);
        }
    }
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:21,代码来源:Transfer.java

示例7: createPopupMenu

import java.awt.MenuItem; //导入方法依赖的package包/类
private PopupMenu createPopupMenu() {
	final PopupMenu popup = new PopupMenu();
	if (allowScreenSwitch) {
		MenuItem switchItem = new MenuItem(Main.getString("text.switchscreen"));
		switchItem.setActionCommand("switch");
		switchItem.addActionListener(this);
		// add to popup
		popup.add(switchItem);
	}
	MenuItem exitItem = new MenuItem(Main.getString("text.exit"));
	exitItem.setActionCommand("exit");
	exitItem.addActionListener(this);
	// add to pop-up menu
	popup.add(exitItem);
	return popup;
}
 
开发者ID:BigMarker,项目名称:deskshare-public,代码行数:17,代码来源:SimpleUI.java

示例8: addExitItem

import java.awt.MenuItem; //导入方法依赖的package包/类
private void addExitItem( PopupMenu popup )
{
    MenuItem exit = new MenuItem( "Exit" );
    exit.addActionListener( new ActionListener()
    {
        @Override
        public void actionPerformed( ActionEvent e )
        {
            // Exits the program
            // plugin.resetLeds();
            // TODO: Decide whether or not LEDS should turn off when
            // program exits.
            //      Pros: You can set a color and then quit the program
            //      Cons: For LEDS to turn off, user has to unload plugins
            System.exit(0);
        }
    });
    popup.add( exit );
}
 
开发者ID:uPaymeiFixit,项目名称:Processing-Arduino-Light-Controller,代码行数:20,代码来源:SystemTrayHandler.java

示例9: initAddCommentMenu

import java.awt.MenuItem; //导入方法依赖的package包/类
/**
 * Initializes the context menu for adding Comments.
 */
private static void initAddCommentMenu() {
	ResourceBundle uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock");
	
	addCommentItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.add_comment"));
    addCommentItem.setActionCommand(ADD_COMMENT_BLOCK);
    addCommentItem.addActionListener(rndBlockMenu);
    addCommentMenu.add(addCommentItem);
    
	cloneItem1 = new MenuItem(uiMessageBundle.getString("ardublock.ui.clone"));
	cloneItem1.setActionCommand(CLONE_BLOCK);
	cloneItem1.addActionListener(rndBlockMenu);
    addCommentMenu.add(cloneItem1);
    
    addCommentMenuInit = true;
    
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:20,代码来源:ContextMenu.java

示例10: initRemoveCommentMenu

import java.awt.MenuItem; //导入方法依赖的package包/类
/**
 * Initializes the context menu for deleting Comments.
 */
private static void initRemoveCommentMenu() {
	ResourceBundle uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock");
	
    removeCommentItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.delete_comment"));
    removeCommentItem.setActionCommand(REMOVE_COMMENT_BLOCK);
    removeCommentItem.addActionListener(rndBlockMenu);

    removeCommentMenu.add(removeCommentItem);
    //rndBlockMenu.add(runBlockItem);
    
	
	cloneItem2 = new MenuItem(uiMessageBundle.getString("ardublock.ui.clone"));
	cloneItem2.setActionCommand(CLONE_BLOCK);
	cloneItem2.addActionListener(rndBlockMenu);
    removeCommentMenu.add(cloneItem2);
    
    removeCommentMenuInit = true;
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:22,代码来源:ContextMenu.java

示例11: makePopupMenu

import java.awt.MenuItem; //导入方法依赖的package包/类
private PopupMenu makePopupMenu() {
	final PopupMenu popup = new PopupMenu();
	final ActionListener rmbListener = new TrayActionRMBListener();
	// Check clipboard text:
	final MenuItem checkClipboardItem = new MenuItem(
			StringTools.getLabel(messages
					.getString("guiMenuCheckClipboard")));
	checkClipboardItem.addActionListener(rmbListener);
	popup.add(checkClipboardItem);
	// Open main window:
	final MenuItem restoreItem = new MenuItem(StringTools.getLabel(messages
			.getString("guiMenuShowMainWindow")));
	restoreItem.addActionListener(rmbListener);
	popup.add(restoreItem);
	// Exit:
	final MenuItem exitItem = new MenuItem(StringTools.getLabel(messages
			.getString("guiMenuQuit")));
	exitItem.addActionListener(rmbListener);
	popup.add(exitItem);
	return popup;
}
 
开发者ID:markkohdev,项目名称:oStorybook,代码行数:22,代码来源:LangToolMain.java

示例12: generateMenu

import java.awt.MenuItem; //导入方法依赖的package包/类
private PopupMenu generateMenu() {
    // 创建弹出菜单
    PopupMenu popup = new PopupMenu();
    // 以下将各个菜单项加入到弹出菜单中
    MenuItem full = new MenuItem("全屏截图");
    full.addActionListener(listener);
    popup.add(full);
    MenuItem select = new MenuItem("选择截图");
    select.addActionListener(listener);
    popup.add(select);
    MenuItem settings = new MenuItem("设置");
    settings.addActionListener(listener);
    popup.add(settings);
    MenuItem quit = new MenuItem("退出");
    quit.addActionListener(listener);
    popup.add(quit);
    return popup;
}
 
开发者ID:mba811,项目名称:loli.io,代码行数:19,代码来源:SwingSystemMenu.java

示例13: StaveActionHandler

import java.awt.MenuItem; //导入方法依赖的package包/类
StaveActionHandler(Stave stave) {
theApp = stave;

      noteContextMenu = new PopupMenu();
      
      editNote = new MenuItem("Edit Note");
      editNote.addActionListener(this);
      noteContextMenu.add(editNote );       
      
      repeatNote = new MenuItem("Repeat Note");
      repeatNote.addActionListener(this);
      noteContextMenu.add(repeatNote ); 		
      
      makeRest = new MenuItem("Change to Rest");
      makeRest.addActionListener(this);
      noteContextMenu.add(makeRest);       
      
      deleteNote = new MenuItem("Delete Note");
      deleteNote.addActionListener(this);
      noteContextMenu.add(deleteNote );       
      
      theApp.add(noteContextMenu);
  }
 
开发者ID:Armaxis,项目名称:jmg,代码行数:24,代码来源:StaveActionHandler.java

示例14: buildTrayIcon

import java.awt.MenuItem; //导入方法依赖的package包/类
public TrayIcon buildTrayIcon() throws IOException {
    PopupMenu popup = new PopupMenu();
    for (MenuItemDefinition mid : menuItems) {
        if (mid instanceof SeperatorMenuItem) {
            popup.addSeparator();
        } else {
            MenuItem item = new MenuItem();
            item.setLabel(mid.getText());
            item.addActionListener(mid);
            popup.add(item);
        }
    }

    TrayIcon ti = new TrayIcon(getImage(imageName), tooltip, popup);
    ti.setImageAutoSize(true);
    return ti;
}
 
开发者ID:devbury,项目名称:mkRemote,代码行数:18,代码来源:TrayIconDefinition.java

示例15: createItems

import java.awt.MenuItem; //导入方法依赖的package包/类
private void createItems()
{
	ih = new ItemHandler();
	MenuItem info = new MenuItem("(c) UploadR v"+Constants.VERSION +" | shortcuts "+(Constants.KEYS_ENABLED ? "enabled" : "disabled"));
	info.setEnabled(false);
	this.add(info);
	for(byte i=0;i<ItemHandler.items.length;++i)
	{
		if(ItemHandler.items[i][0].equals("s"))
		{
			this.addSeparator();
			continue;
		}
		MenuItem item = new MenuItem(ItemHandler.items[i][0]);
		item.setActionCommand(ItemHandler.items[i][1]);
		item.addActionListener(ih);
		this.add(item);
	}
}
 
开发者ID:Hual,项目名称:UploadR,代码行数:20,代码来源:Menu.java


注:本文中的java.awt.MenuItem.addActionListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。