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);

 

Related Examples

相关文章:

  • 2022-01-13
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-08-28
  • 2021-11-13
  • 2021-07-22
猜你喜欢
  • 2021-12-15
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-03
相关资源
相似解决方案