List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:SwingWorkerTest.java
public SwingWorkerFrame() { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); textArea = new JTextArea(); add(new JScrollPane(textArea)); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); statusLine = new JLabel(" "); add(statusLine, BorderLayout.SOUTH); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/* www . jav a 2 s .co m*/ JMenu menu = new JMenu("File"); menuBar.add(menu); openItem = new JMenuItem("Open"); menu.add(openItem); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // show file chooser dialog int result = chooser.showOpenDialog(null); // if file selected, set it as icon of the label if (result == JFileChooser.APPROVE_OPTION) { textArea.setText(""); openItem.setEnabled(false); textReader = new TextReader(chooser.getSelectedFile()); textReader.execute(); cancelItem.setEnabled(true); } } }); cancelItem = new JMenuItem("Cancel"); menu.add(cancelItem); cancelItem.setEnabled(false); cancelItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { textReader.cancel(true); } }); }
From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java
private void initMenu() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/* w ww. ja va2 s . c o m*/ JMenuItem open = new JMenuItem("Open Project Folder", KeyEvent.VK_O); open.setMnemonic(KeyEvent.VK_O); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptForGradleBaseDir(); refresh(); } }); fileMenu.add(open); JMenuItem refresh = new JMenuItem("Refresh"); refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { refresh(); } }); fileMenu.add(refresh); fileMenu.addSeparator(); JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X); exit.setMnemonic(KeyEvent.VK_X); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exit); setJMenuBar(menuBar); }
From source file:components.MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from w ww .j a v a 2s. c o m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java
public PerformanceResultDialog(PerformanceResultsData data) { super((Frame) null, "Performance test results"); setSize(1000, 800);//from ww w . j av a 2 s. c o m JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem savePerformanceMenuItem = new JMenuItem("Save Performance"); fileMenu.add(savePerformanceMenuItem); savePerformanceMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save as PNG..."); int result = fileChooser.showSaveDialog(PerformanceResultDialog.this); if (JFileChooser.APPROVE_OPTION == result) { File file = fileChooser.getSelectedFile(); try { ChartUtilities.saveChartAsPNG(file, performanceChart, 1024, 768); } catch (IOException e) { JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage()); } } } }); JMenuItem saveMemoryMenuItem = new JMenuItem("Save Memory"); fileMenu.add(saveMemoryMenuItem); saveMemoryMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save as PNG..."); int result = fileChooser.showSaveDialog(PerformanceResultDialog.this); if (JFileChooser.APPROVE_OPTION == result) { File file = fileChooser.getSelectedFile(); try { ChartUtilities.saveChartAsPNG(file, memoryChart, 1024, 768); } catch (IOException e) { JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage()); } } } }); // memory chart memoryChart = getMemoryChart(data.getIntervalSize(), data.getMemory()); // performance chart performanceChart = getPerformanceChart(data.getIntervalSize(), data.getPerformance(), data.getExpectedRevokedCount()); Container container = getContentPane(); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); if (null != performanceChart) { splitPane.setTopComponent(new ChartPanel(performanceChart)); } if (null != memoryChart) { splitPane.setBottomComponent(new ChartPanel(memoryChart)); } splitPane.setDividerLocation(getHeight() / 2); splitPane.setDividerSize(1); container.add(splitPane); setVisible(true); }
From source file:ToolBarTest.java
public ToolBarFrame() { setTitle("ToolBarTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add a panel for color change panel = new JPanel(); add(panel, BorderLayout.CENTER); // set up actions Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE); Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.YELLOW); Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED); Action exitAction = new AbstractAction("Exit", new ImageIcon("exit.gif")) { public void actionPerformed(ActionEvent event) { System.exit(0);//from w ww .j av a 2s . c o m } }; exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit"); // populate tool bar JToolBar bar = new JToolBar(); bar.add(blueAction); bar.add(yellowAction); bar.add(redAction); bar.addSeparator(); bar.add(exitAction); add(bar, BorderLayout.NORTH); // populate menu JMenu menu = new JMenu("Color"); menu.add(yellowAction); menu.add(blueAction); menu.add(redAction); menu.add(exitAction); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:ImageProcessingTest.java
public ImageProcessingFrame() { setTitle("ImageProcessingTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); add(new JComponent() { public void paintComponent(Graphics g) { if (image != null) g.drawImage(image, 0, 0, null); }/* w w w.ja v a2s . co m*/ }); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile(); } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenu editMenu = new JMenu("Edit"); JMenuItem blurItem = new JMenuItem("Blur"); blurItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float weight = 1.0f / 9.0f; float[] elements = new float[9]; for (int i = 0; i < 9; i++) elements[i] = weight; convolve(elements); } }); editMenu.add(blurItem); JMenuItem sharpenItem = new JMenuItem("Sharpen"); sharpenItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 5.f, -1.0f, 0.0f, -1.0f, 0.0f }; convolve(elements); } }); editMenu.add(sharpenItem); JMenuItem brightenItem = new JMenuItem("Brighten"); brightenItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float a = 1.1f; // float b = 20.0f; float b = 0; RescaleOp op = new RescaleOp(a, b, null); filter(op); } }); editMenu.add(brightenItem); JMenuItem edgeDetectItem = new JMenuItem("Edge detect"); edgeDetectItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 4.f, -1.0f, 0.0f, -1.0f, 0.0f }; convolve(elements); } }); editMenu.add(edgeDetectItem); JMenuItem negativeItem = new JMenuItem("Negative"); negativeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { short[] negative = new short[256 * 1]; for (int i = 0; i < 256; i++) negative[i] = (short) (255 - i); ShortLookupTable table = new ShortLookupTable(0, negative); LookupOp op = new LookupOp(table, null); filter(op); } }); editMenu.add(negativeItem); JMenuItem rotateItem = new JMenuItem("Rotate"); rotateItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (image == null) return; AffineTransform transform = AffineTransform.getRotateInstance(Math.toRadians(5), image.getWidth() / 2, image.getHeight() / 2); AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC); filter(op); } }); editMenu.add(rotateItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); menuBar.add(editMenu); setJMenuBar(menuBar); }
From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java
/** * Constructs DBMenuBar. Adds the menu and menuitems. * * @param graphicsRunner the JFrame that created this * @param desktop the DBDesktopPane in the JFrame *///from w w w . j a va 2s .c om public DBMenuBar(GraphicsRunner graphicsRunner, DBDesktopPane desktop) { super(); gr = graphicsRunner; this.desktop = desktop; //Set up the menu JMenu menu = new JMenu("File"); add(menu); //Set up the menu items. JMenuItem menuItem = new JMenuItem("New"); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("new"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Open"); menuItem.setMnemonic(KeyEvent.VK_O); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("open"); menuItem.addActionListener(this); menuItem.setLayout(new MigLayout()); menu.add(menuItem); menuItem = new JMenuItem("Save"); menuItem.setMnemonic(KeyEvent.VK_S); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("save"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Save As"); menuItem.setActionCommand("saveas"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Print Current Page"); menuItem.setMnemonic(KeyEvent.VK_P); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("printpage"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Print Show"); menuItem.setActionCommand("printshow"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Print Dot Sheets"); menuItem.setActionCommand("printdotsheets"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Quit"); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("quit"); menuItem.addActionListener(this); menu.add(menuItem); menu = new JMenu("Edit"); add(menu); menuItem = new JMenuItem("Undo"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("undo"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Redo"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("redo"); menuItem.addActionListener(this); menu.add(menuItem); menu = new JMenu("Settings"); add(menu); menuItem = new JMenuItem("Toggle Gridlines"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("togglegrid"); menuItem.addActionListener(this); menuItem.setForeground(Main.getState().getSettings().shouldShowGrid() ? Color.BLACK : Color.RED); menu.add(menuItem); menuItem = new JMenuItem("Toggle Dot Names"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)); menuItem.setActionCommand("togglenames"); menuItem.addActionListener(this); menuItem.setForeground(Main.getState().getSettings().shouldShowNames() ? Color.BLACK : Color.RED); menu.add(menuItem); menuItem = new JMenuItem("Toggle Text Box"); menuItem.setActionCommand("toggletext"); menuItem.addActionListener(this); menuItem.setForeground(Main.getState().getSettings().shouldShowText() ? Color.BLACK : Color.RED); menu.add(menuItem); menuItem = new JMenuItem("Color Code Dots by Instrument"); menuItem.setActionCommand("colordots"); menuItem.addActionListener(this); menuItem.setForeground(Main.getState().getSettings().shouldColorDots() ? Color.BLACK : Color.RED); menu.add(menuItem); menuItem = new JMenuItem(); menuItem.setText(Main.getState().getSettings().useCollegeHashes() ? "Change to High School Hashes" : "Change to College Hashes"); menuItem.setActionCommand("changehash"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("Change Font Size"); menuItem.setActionCommand("fontsize"); menuItem.addActionListener(this); menu.add(menuItem); //add(Box.createHorizontalStrut(menu.getPreferredSize().width)); //add these to the menubar itself menuItem = new JMenuItem("Play"); menuItem.setMaximumSize(new Dimension(menuItem.getPreferredSize().width, Integer.MAX_VALUE)); menuItem.setActionCommand("play"); menuItem.addActionListener(this); add(menuItem); add(Box.createHorizontalGlue()); menu = new JMenu("Help"); add(menu); menuItem = new JMenuItem("Help"); menuItem.setActionCommand("help"); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem("About"); menuItem.setActionCommand("about"); menuItem.addActionListener(this); menu.add(menuItem); }
From source file:MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/* w w w . jav a2 s . c o m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; // Create the menu bar. menuBar = new JMenuBar(); // Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); // a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); // menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); // a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); // a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); // a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); // Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:components.MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from ww w . j a va 2 s . co m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:JiltBefore.java
JiltBefore(String s) { super("JiltBefore: " + s); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); mb = new JMenuBar(); setJMenuBar(mb);//from w w w . jav a2 s . c o m JMenuItem mi; // The File Menu... fm = new JMenu("File"); fm.add(mi = new JMenuItem("Open")); mi.addActionListener(this); fm.add(mi = new JMenuItem("Close")); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new JMenuItem("Print")); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new JMenuItem("Exit")); exitItem = mi; // save for action handler mi.addActionListener(this); mb.add(fm); // The Options Menu... om = new JMenu("Options"); fm.add(mi = new JMenuItem("Enable")); opSubm = new JMenu("SubOptions"); opSubm.add(new JMenuItem("Alpha")); opSubm.add(new JMenuItem("Gamma")); opSubm.add(new JMenuItem("Delta")); om.add(opSubm); mb.add(om); // The Help Menu... hm = new JMenu("Help"); hm.add(mi = new JMenuItem("About")); mi.addActionListener(this); hm.add(mi = new JMenuItem("Topics")); mi.addActionListener(this); mb.add(hm); // mb.setHelpMenu(hm); // needed for portability (Motif, etc.). // the main window cp.add(new JLabel("Menu Demo Window")); // pack(); setSize(250, 200); }