本文整理汇总了Java中java.awt.MenuItem类的典型用法代码示例。如果您正苦于以下问题:Java MenuItem类的具体用法?Java MenuItem怎么用?Java MenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MenuItem类属于java.awt包,在下文中一共展示了MenuItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例3: register_system_tray_icon
import java.awt.MenuItem; //导入依赖的package包/类
@Test
public void register_system_tray_icon() throws ExecutionException, InterruptedException {
final SystemTraySupport systemTraySupport = this.applicationContext.getBean(SystemTraySupport.class);
final MenuItem testItem = new MenuItem("DISABLED_ON_CLICK");
final ActionListener disableOnClick = e -> testItem.setEnabled(false);
final Map<MenuItem, ActionListener> menuItems = new HashMap<MenuItem, ActionListener>() {{
this.put(testItem, disableOnClick);
}};
final SystemTrayIcon trayIcon = this.systemTrayIconWith(menuItems);
systemTraySupport.registerTrayIcon(trayIcon)
.whenCompleteAsync((res, err) -> assertThat(res.isSuccess()).isTrue())
.thenApply(Try::get)
.whenCompleteAsync((res, err) -> assertThat(systemTraySupport.getTrayIcons()).containsExactly(res))
.whenCompleteAsync((res, err) -> systemTraySupport.removeTrayIcon(res))
.thenAccept(icon -> assertThat(systemTraySupport.getTrayIcons()).doesNotContain(icon))
.toCompletableFuture().get();
}
示例4: systemTrayIconWith
import java.awt.MenuItem; //导入依赖的package包/类
private SystemTrayIcon systemTrayIconWith(final Map<MenuItem, ActionListener> menuItems) {
return new SystemTrayIcon() {
@Override
public String getLabel() {
return TRAY_LABEL;
}
@Override
public URL getIcon() {
return TRAY_ICON_URL;
}
@Override
public Map<MenuItem, ActionListener> getMenuItems() {
return menuItems;
}
};
}
示例5: 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;
}
示例6: addMenuItems
import java.awt.MenuItem; //导入依赖的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);
}
}
示例7: 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;
}
示例8: createMenu
import java.awt.MenuItem; //导入依赖的package包/类
/**
* creates a PopUp menu for the TrayIcon
*
* @return PopUp menu for the TrayIcon
*/
private PopupMenu createMenu() {
PopupMenu menu = new PopupMenu("TimeTray " + this.VERSION);
// about item
MenuItem menuSettings = new MenuItem("Settings");
menuSettings.setActionCommand("settings");
menu.add(menuSettings);
// exit item
MenuItem menuExit = new MenuItem("Quit");
menuExit.setActionCommand("quit");
menu.add(menuExit);
menu.addActionListener(this);
return menu;
}
示例9: 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);
}
}
示例10: 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);
}
}
}
示例11: 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;
}
示例12: 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 );
}
示例13: actionPerformed
import java.awt.MenuItem; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
String label = ((MenuItem) e.getSource()).getLabel();
if (CREATE_NOTE_TEXT.equals(label)) {
createNote();
} else if (SHOW_ALL_NOTES_TEXT.equals(label)) {
showNotes(ALL);
} else if (HIDE_ALL_NOTES_TEXT.equals(label)) {
showNotes(NONE);
} else if (PREFERENCES_TEXT.equals(label)) {
new PreferencesDialog(frame, preferencesManager.getPreferences()).setVisible(true);
} else if (ABOUT_TEXT.equals(label)) {
JLabel about = new JLabel(ABOUT_DIALOG_TEXT);
about.setIcon(Icon.getJStickyNotesImageIcon(48));
JOptionPane.showMessageDialog(frame, about, ABOUT_DIALOG_TITLE_TEXT, JOptionPane.PLAIN_MESSAGE);
} else if (EXIT_TEXT.equals(label)) {
System.exit(0);
}
}
示例14: 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;
}
示例15: 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;
}