Java Window Menu

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.