List of usage examples for java.awt MenuShortcut MenuShortcut
public MenuShortcut(int key)
From source file:AnotherMenuDemo.java
AnotherMenuDemo(String s) { super("MenuDemo: " + s); Container cp = this; cp.setLayout(new FlowLayout()); mb = new MenuBar(); setMenuBar(mb); // Frame implements MenuContainer MenuItem mi;/*ww w.j av a2 s. com*/ // The File Menu... fm = new Menu("File"); fm.add(mi = new MenuItem("Open", new MenuShortcut('O'))); mi.addActionListener(this); fm.add(mi = new MenuItem("Close", new MenuShortcut('W'))); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new MenuItem("Print", new MenuShortcut('P'))); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new MenuItem("Exit", new MenuShortcut('Q'))); exitItem = mi; // save for action handler mi.addActionListener(this); mb.add(fm); // The Options Menu... om = new Menu("Options"); cb = new CheckboxMenuItem("AutoSave"); cb.setState(true); cb.addItemListener(this); om.add(cb); opSubm = new Menu("SubOptions"); opSubm.add(new MenuItem("Alpha")); opSubm.add(new MenuItem("Gamma")); opSubm.add(new MenuItem("Delta")); om.add(opSubm); mb.add(om); // The Help Menu... hm = new Menu("Help"); hm.add(mi = new MenuItem("About")); mi.addActionListener(this); hm.add(mi = new MenuItem("Topics")); mi.addActionListener(this); mb.add(hm); mb.setHelpMenu(hm); // needed for portability (Motif, etc.). // the main window cp.add(new Label("Menu Demo Window", 200, 150)); pack(); }
From source file:PlayerOfMedia.java
/*************************************************************************** * Construct a PlayerOfMedia. The Frame will have the title supplied by the * user. All initial actions on the PlayerOfMedia object are initiated * through its menu (or shotcut key)./* w w w . j av a2 s . c om*/ **************************************************************************/ PlayerOfMedia(String name) { super(name); /////////////////////////////////////////////////////////// // Setup the menu system: a "File" menu with Open and Quit. /////////////////////////////////////////////////////////// bar = new MenuBar(); fileMenu = new Menu("File"); MenuItem openMI = new MenuItem("Open...", new MenuShortcut(KeyEvent.VK_O)); openMI.setActionCommand("OPEN"); openMI.addActionListener(this); fileMenu.add(openMI); MenuItem quitMI = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q)); quitMI.addActionListener(this); quitMI.setActionCommand("QUIT"); fileMenu.add(quitMI); bar.add(fileMenu); setMenuBar(bar); /////////////////////////////////////////////////////// // Layout the frame, its position on screen, and ensure // window closes are dealt with properly, including // relinquishing the resources of any Player. /////////////////////////////////////////////////////// setLayout(new BorderLayout()); setLocation(100, 100); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (player != null) { player.stop(); player.close(); } System.exit(0); } }); ///////////////////////////////////////////////////// // Build the Dialog box by which the user can select // the media to play. ///////////////////////////////////////////////////// selectionDialog = new Dialog(this, "Media Selection"); Panel pan = new Panel(); pan.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); mediaName = new TextField(40); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; pan.add(mediaName, gbc); choose = new Button("Choose File..."); gbc.ipadx = 10; gbc.ipady = 10; gbc.gridx = 2; gbc.gridwidth = 1; pan.add(choose, gbc); choose.addActionListener(this); open = new Button("Open"); gbc.gridy = 1; gbc.gridx = 1; pan.add(open, gbc); open.addActionListener(this); cancel = new Button("Cancel"); gbc.gridx = 2; pan.add(cancel, gbc); cancel.addActionListener(this); selectionDialog.add(pan); selectionDialog.pack(); selectionDialog.setLocation(200, 200); //////////////////////////////////////////////////// // Build the error Dialog box by which the user can // be informed of any errors or problems. //////////////////////////////////////////////////// errorDialog = new Dialog(this, "Error", true); errorLabel = new Label(""); errorDialog.add(errorLabel, "North"); ok = new Button("OK"); ok.addActionListener(this); errorDialog.add(ok, "South"); errorDialog.pack(); errorDialog.setLocation(150, 300); Manager.setHint(Manager.PLUGIN_PLAYER, new Boolean(true)); }
From source file:Unicode.java
/** Convenience routine to make a MenuItem */ public MenuItem mkMenuItem(ResourceBundle b, String menu, String name) { String miLabel;/*from w ww . j av a 2s . c o m*/ try { miLabel = b.getString(menu + "." + name + ".label"); } catch (MissingResourceException e) { miLabel = name; } String key = null; try { key = b.getString(menu + "." + name + ".key"); } catch (MissingResourceException e) { key = null; } if (key == null) return new MenuItem(miLabel); else return new MenuItem(miLabel, new MenuShortcut(key.charAt(0))); }
From source file:org.rapidcontext.app.ui.ControlPanel.java
/** * Initializes the frame menu.//from www . j av a 2 s . c o m */ private void initializeMenu() { Menu menu; MenuItem item; // Create file menu if (!SystemUtils.IS_OS_MAC_OSX) { menu = new Menu("File"); item = new MenuItem("Exit", new MenuShortcut(KeyEvent.VK_Q)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { quit(); } }); menu.add(item); menuBar.add(menu); menu = new Menu("Help"); item = new MenuItem("About"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { about(); } }); menu.add(item); menuBar.add(menu); } // Fix Mac OS specific menus if (SystemUtils.IS_OS_MAC_OSX) { try { MacApplication.get().setAboutHandler(new ActionListener() { public void actionPerformed(ActionEvent evt) { about(); } }); MacApplication.get().setPreferencesHandler(null); } catch (Exception ignore) { // Errors are ignored } } }