Create a Window program (JFrame), the title bar named "Browser", there is a menu bar, there are "file", "edit", "View" 3 menus. The "File" menu has two menu items, one is "open", one is "save", "open" item as a sub-menu, there are two menu items "open x" and "Open Y", "save" item is normal menu item. The Edit menu is "Copy" on one menu item. "View" has two menu items "Stop" and "refresh". Add the appropriate shortcut keys on the menu and menu items.
ImportJavax.swing.JFrame; ImportJavax.swing.JMenu; ImportJavax.swing.JMenuBar; ImportJavax.swing.JMenuItem; Public classFrame { Public Static voidMain (string[] args) {window win=NewWindow ("Browser"); } } classWindowextendsjframe{JMenuBar Mmenbar=NewJMenuBar (); JMenu Mmenufile=NewJMenu ("File"), Mmenuedit=NewJMenu ("Edit"), Mmenuselect=NewJMenu ("View"), Mmenuopen=NewJMenu ("Open"); JMenuItem mitemcopy=NewJMenuItem ("Copy"), Mitemstop=NewJMenuItem ("Stop"), Mitemopenx=NewJMenuItem ("Open X"), Mitemopeny=NewJMenuItem ("Open y"), Mitemrefresh=NewJMenuItem ("Refresh"), Mitemsave=NewJMenuItem ("Save"); Window (String title) {Settitle (title); SetSize (400,300); SetLocation (200,200); SetVisible (true); Mmenuopen.setmnemonic (O); Mmenuopen.add (Mitemopenx); Mmenuopen.add (Mitemopeny); Mmenufile.add (Mmenuopen); Mmenufile.add (Mitemsave); Mmenufile.setmnemonic (F); Mmenuedit.add (mitemcopy); Mmenuedit.setmnemonic (E); Mmenuselect.add (Mitemstop); Mmenuselect.add (Mitemrefresh); Mmenuselect.setmnemonic (S); Mmenbar.add (Mmenufile); Mmenbar.add (Mmenuedit); Mmenbar.add (Mmenuselect); Setjmenubar (Mmenbar); Validate (); Setdefaultcloseoperation (Jframe.dispose_on_close); } }
Operation Result:
Java Window Menu