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


Java JMenuItem.addActionListener方法代码示例

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


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

示例1: buildViewsMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
protected JMenu buildViewsMenu() {
    JMenu views = new JMenu("Views");

    JMenuItem inBox = new JMenuItem("Open In-Box");
    JMenuItem outBox = new JMenuItem("Open Out-Box");
    outBox.setEnabled(false);

    inBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openInBox();
        }
    });

    views.add(inBox);
    views.add(outBox);
    return views;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:MetalworksFrame.java

示例2: TreeJavaFilePopupMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
public TreeJavaFilePopupMenu( FileNavigator navigator)
{
    super(navigator);
    
    this.opener = navigator.opener;
    
    compile = new JMenuItem( "Compile File");
    run = new JMenuItem( "Run File");
    
    addSeparator();
    add( compile);
    add( run);
    
    compile.addActionListener( this);
    run.addActionListener( this);
}
 
开发者ID:bufferhe4d,项目名称:call-IDE,代码行数:17,代码来源:TreeJavaFilePopupMenu.java

示例3: createDisplayMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void createDisplayMenu() {
	displayMenu = new JMenu("Display");
	displayMenu.setMnemonic(KeyEvent.VK_D);
	fileMenu.getAccessibleContext().setAccessibleDescription(
			"Display the problem and solution.");
	menuBar.add(displayMenu);

	problemItem = new JMenuItem("Problem");
	problemItem.setMnemonic(KeyEvent.VK_P);
	problemItem.addActionListener(menuListener);
	problemItem.setEnabled(false);
	displayMenu.add(problemItem);

	solutionItem = new JMenuItem("Solution");
	solutionItem.setMnemonic(KeyEvent.VK_S);
	solutionItem.addActionListener(menuListener);
	solutionItem.setEnabled(false);
	displayMenu.add(solutionItem);
}
 
开发者ID:moment-of-peace,项目名称:AI-RRT-Motion-Planning,代码行数:20,代码来源:Visualiser.java

示例4: createMarketMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
 * Creates menu items for some goods in a market.
 *
 * @param marketLabel The {@code MarketLabel} to create entries for.
 */
private void createMarketMenu(MarketLabel marketLabel) {
    final AbstractGoods ag = marketLabel.getAbstractGoods();
    final Player player = freeColClient.getMyPlayer();

    this.setLabel(Messages.message("cargo"));
    JMenuItem name = new JMenuItem(
        Messages.getName(ag) + " (" + Messages.message("colopedia") + ")",
        new ImageIcon(
            gui.getImageLibrary().getSmallIconImage(ag.getType())));
    name.addActionListener((ActionEvent ae) -> {
            gui.showColopediaPanel(ag.getType().getId());
        });
    this.add(name);

    final Europe europe = this.freeColClient.getMyPlayer().getEurope();
    addMarketItems(ag, europe);

    if (!player.canTrade(ag.getType())) {
        addPayArrears(ag.getType());
    }
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:27,代码来源:QuickActionMenu.java

示例5: createMenuBar

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
 * Set up the menu bar
 */
JMenuBar createMenuBar() {
	JMenuBar menuBar = new JMenuBar();
	// File
	JMenu menuFile = new JMenu(textBundle.get("SwingAppleCommander.MenuFile")); //$NON-NLS-1$
	// File->Open
    JMenuItem openItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileOpen")); //$NON-NLS-1$
    openItem.addActionListener(this);
	menuFile.add(openItem);
	// File->Close
    JMenuItem closeItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileClose")); //$NON-NLS-1$
    closeItem.addActionListener(this);
	menuFile.add(closeItem);
	// File->New
    JMenuItem newItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileNew")); //$NON-NLS-1$
    newItem.addActionListener(this);
	menuFile.add(newItem);
	// File->Exit
    JMenuItem quitItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileQuit")); //$NON-NLS-1$
    quitItem.addActionListener(this);
	menuFile.add(quitItem);
	menuBar.add(menuFile);
	return menuBar;
}
 
开发者ID:AppleCommander,项目名称:AppleCommander,代码行数:27,代码来源:SwingAppleCommander.java

示例6: FileSaver

import javax.swing.JMenuItem; //导入方法依赖的package包/类
public FileSaver(JProgressBar bar, JLabel label) {
	this.bar = bar;
	this.label = label;
	final JPopupMenu menu = new JPopupMenu("Cancel");
	final JMenuItem item = new JMenuItem("Cancel");
	item.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			setCancel(true);
		}
	});
	menu.add(item);
	this.label.addMouseListener(new MouseAdapter() {
		public void mouseClicked(MouseEvent ev) {
			if (SwingUtilities.isRightMouseButton(ev) && isExtracting())
				menu.show(ev.getComponent(), ev.getX(), ev.getY());
		}
	});
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:20,代码来源:FileSaver.java

示例7: menuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/** Construct a new JMenuItem then add it to an existing JMenu.
 * @param parent - the JMenu to add this JMenuItem into (or null if you don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 * <p> If one positive number  a is supplied, we call setMnemonic(a)
 * <p> If two positive numbers a and b are supplied, and a!=VK_ALT, and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 * <p> If two positive numbers a and b are supplied, and a==VK_ALT or a==VK_SHIFT, we call setAccelerator(a | b)
 * <p> If an ActionListener is supplied, we call addActionListener(x)
 * <p> If an Boolean x      is supplied, we call setEnabled(x)
 * <p> If an Icon x         is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem (JMenu parent, String label, Object... attrs) {
   JMenuItem m = new JMenuItem(label, null);
   int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
   boolean hasMnemonic = false;
   for(Object x: attrs) {
      if (x instanceof Character || x instanceof Integer) {
         int k = (x instanceof Character) ? ((int)((Character)x)) : ((Integer)x).intValue();
         if (k < 0) continue;
         if (k==KeyEvent.VK_ALT)   { hasMnemonic = true; accelMask = accelMask | InputEvent.ALT_MASK;   continue; }
         if (k==KeyEvent.VK_SHIFT) { hasMnemonic = true; accelMask = accelMask | InputEvent.SHIFT_MASK; continue; }
         if (!hasMnemonic) { m.setMnemonic(k); hasMnemonic=true; } else m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
      }
      if (x instanceof ActionListener) m.addActionListener((ActionListener)x);
      if (x instanceof Icon) m.setIcon((Icon)x);
      if (x instanceof Boolean) m.setEnabled((Boolean)x);
   }
   if (parent!=null) parent.add(m);
   return m;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:31,代码来源:OurUtil.java

示例8: addBoardItems

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private boolean addBoardItems(final UnitLabel unitLabel, Location loc) {
    final Unit tempUnit = unitLabel.getUnit();
    if (tempUnit.isCarrier()) return false;

    final InGameController igc = freeColClient.getInGameController();

    boolean added = false;
    for (Unit unit : transform(loc.getUnitList(), u ->
            (u.isCarrier() && u.canCarryUnits() && u.canAdd(tempUnit)
                && tempUnit.getLocation() != u))) {
        StringTemplate template
            = StringTemplate.template("quickActionMenu.board")
                .addStringTemplate("%unit%",
                    unit.getLabel(Unit.UnitLabelType.NATIONAL));
        JMenuItem menuItem = Utility.localizedMenuItem(template);
        menuItem.addActionListener((ActionEvent ae) -> {
                igc.boardShip(tempUnit, unit);
            });
        this.add(menuItem);
        added = true;
    }
    return added;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:24,代码来源:QuickActionMenu.java

示例9: addCarAction

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void addCarAction(final Car c)
{
    JMenuItem lbl = new JMenuItem(String.format("%s %s #%s %s %s", c.getClassCode(), Database.d.getEffectiveIndexStr(c), c.getNumber(), c.getMake(), c.getModel()));
    lbl.setFont(itemFont);
    lbl.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            Messenger.sendEvent(MT.CAR_CHANGE, c.getCarId());
    }});

    if (Database.d.isInOrder(DataEntry.state.getCurrentEventId(), c.getCarId(), DataEntry.state.getCurrentCourse()))
    {
        lbl.setEnabled(false);
        lbl.setForeground(superLightGray);
    }

    menu.add(lbl);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:18,代码来源:DriverContextMenu.java

示例10: createMenuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
public JMenuItem createMenuItem(JMenu menu, String name, String description) {
	// a group of JMenuItems
	JMenuItem menuItem = new JMenuItem(name);

	menuItem.getAccessibleContext().setAccessibleDescription(description);
	menuItem.addActionListener(this);

	menu.add(menuItem);
	return menuItem;
}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:11,代码来源:MenuCreator.java

示例11: add

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private boolean add(LogisimMenuItem item, String display) {
	if (shouldShow(item)) {
		JMenuItem menu = new JMenuItem(display);
		items.put(item, menu);
		menu.setEnabled(isEnabled(item));
		menu.addActionListener(listener);
		add(menu);
		return true;
	} else {
		return false;
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:13,代码来源:EditPopup.java

示例12: loadAPalette

import javax.swing.JMenuItem; //导入方法依赖的package包/类
protected void loadAPalette(String importPath, String lutGMAPath) {
	File dir = new File(importPath);
	if( !dir.exists())return;

		try {
			Palette p = new Palette(dir);
			JMenuItem item = paletteMenu.add(new JMenuItem(
				p.toString(), p.getIcon()));
			item.setActionCommand("Loaded Palette");
			item.addActionListener(palListener);
			FilesUtil.copyFile(importPath, lutGMAPath);
			palettes.put( p.toString(), p);
		} catch(Exception ex) {
		}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:16,代码来源:RenderingTools.java

示例13: menuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
 * Construct a new JMenuItem then add it to an existing JMenu.
 * 
 * @param parent - the JMenu to add this JMenuItem into (or null if you
 *            don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 *            <p>
 *            If one positive number a is supplied, we call setMnemonic(a)
 *            <p>
 *            If two positive numbers a and b are supplied, and a!=VK_ALT,
 *            and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 *            <p>
 *            If two positive numbers a and b are supplied, and a==VK_ALT or
 *            a==VK_SHIFT, we call setAccelerator(a | b)
 *            <p>
 *            If an ActionListener is supplied, we call addActionListener(x)
 *            <p>
 *            If an Boolean x is supplied, we call setEnabled(x)
 *            <p>
 *            If an Icon x is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem(JMenu parent, String label, Object... attrs) {
	JMenuItem m = new JMenuItem(label, null);
	int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
	boolean hasMnemonic = false;
	for (Object x : attrs) {
		if (x instanceof Character || x instanceof Integer) {
			int k = (x instanceof Character) ? ((int) ((Character) x)) : ((Integer) x).intValue();
			if (k < 0)
				continue;
			if (k == KeyEvent.VK_ALT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.ALT_MASK;
				continue;
			}
			if (k == KeyEvent.VK_SHIFT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.SHIFT_MASK;
				continue;
			}
			if (!hasMnemonic) {
				m.setMnemonic(k);
				hasMnemonic = true;
			} else
				m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
		}
		if (x instanceof ActionListener)
			m.addActionListener((ActionListener) x);
		if (x instanceof Icon)
			m.setIcon((Icon) x);
		if (x instanceof Boolean)
			m.setEnabled((Boolean) x);
	}
	if (parent != null)
		parent.add(m);
	return m;
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:59,代码来源:OurUtil.java

示例14: getToolbarPresenter

import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
public Component getToolbarPresenter() {
   
        JPopupMenu menu = new JPopupMenu();
        JButton button = DropDownButtonFactory.createDropDownButton(
                new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
        final JMenuItem item = new JMenuItem(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText")));
        item.setEnabled(isEnabled());

        addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                String propName = evt.getPropertyName();
                if ("enabled".equals(propName)) {
                    item.setEnabled((Boolean) evt.getNewValue());
                } else if ("menuText".equals(propName)) {
                    item.setText(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue()));
                }
            }
        });

        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainProjectActionWithHistory.this.actionPerformed(e);
            }
        });
       
        org.openide.awt.Actions.connect(button, this);
        menu.addPopupMenuListener(this);
        return button;
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:MainProjectActionWithHistory.java

示例15: createMenuItems

import javax.swing.JMenuItem; //导入方法依赖的package包/类
public JMenuItem[] createMenuItems () {
    FiltersDescription filtersDesc = filters.getDescription();
    ArrayList menuItems = new ArrayList();
    for (int i = 0; i < filtersDesc.getFilterCount(); i++) {
        String filterName = filtersDesc.getName(i);
        JMenuItem menuItem = new JCheckBoxMenuItem(
                filtersDesc.getDisplayName(i), filters.isSelected(filterName)); 
        menuItem.addActionListener(this);
        menuItem.putClientProperty(PROP_FILTER_NAME, filterName);
        menuItems.add(menuItem);
    }
    return (JMenuItem[])menuItems.toArray(new JMenuItem[]{});
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:FilterActions.java


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