JMenuItem 和 JMenu 有什么区别

what is the difference between JMenuItem and JMenu

JMenuItemJMenu 有什么区别?

JMenu m;
JMenuItem i;

A JMenu 是菜单本身,或者如文档所述:

An implementation of a menu -- a popup window containing JMenuItems that is displayed when the user selects an item on the JMenuBar.

A JMenuItem 是此类菜单中的单个项目。或者,如文档所述:

An implementation of an item in a menu. A menu item is essentially a button sitting in a list. When the user selects the "button", the action associated with the menu item is performed.

JMenu 扩展了 JMenuItem。 不同的是,JMenu 是一个 item,它可以包含其他 JMenuItem。将其视为子菜单。