Creating a JMenuBar, JMenu, and JMenuItem Component

When the user selects a menu item, it fires an action event.
// Create the menu bar JMenuBar menuBar = new JMenuBar(); // Create a menu JMenu menu = new JMenu("Menu Label"); menuBar.add(menu); // Create a menu item JMenuItem item = new JMenuItem("Item Label"); item.addActionListener(actionListener); menu.add(item); // Install the menu bar in the frame frame.setJMenuBar(menuBar);

Comments

10 Mar 2010 - 11:13pm by Archielsie (not verified)

meaning about JMenu class

15 Mar 2010 - 6:15pm by Anonymous (not verified)

// Create the menu bar JMenuBar menuBar = new JMenuBar(); // Create a menu JMenu menu = new JMenu("Menu Label"); menuBar.add(menu); // Create a menu item JMenuItem item = new JMenuItem("Item Label"); item.addActionListener(actionListener); menu.add(item); // Install the menu bar in the frame frame.setJMenuBar(menuBar);

18 Mar 2010 - 6:45pm by Anonymous (not verified)

java is hard..ahh..:'(

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.