Design of Windows application in Java

Source: Internet
Author: User

1. 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.

Package window;

Import java.awt.event.InputEvent;
Import java.awt.event.KeyEvent;

Import javax.swing.*;


public class Frame {
public static void Main (string[] args) {
TODO auto-generated method stubs
Firstwindow win=new Firstwindow ("browser");
}

}

Class Firstwindow extends jframe{
JMenuBar menubar;
JMenu Menu1,menu2,menu3,menu4;
JMenuItem ITEM1,ITEM2,ITEM3,ITEM4,ITEM5;
Firstwindow (String s) {
Settitle (s);
SetSize (400,300);
SetLocation (120,120);
SetVisible (TRUE);

Menubar=new JMenuBar ();
Menu1=new jmenu ("File (F)");
Menu1.setmnemonic (' F ');
Menu2=new JMenu ("edit (E)");
Menu2.setmnemonic (' F ');
Menu3=new JMenu ("View (V)");
Menu3.setmnemonic (' V ');

Menu4=new JMenu ("Open (O)");
Menu4.setmnemonic (' O ');


Item2=new JMenuItem ("Save", New ImageIcon ("Save.gif"));
Item2.setaccelerator (Keystroke.getkeystroke (keyevent.vk_s,inputevent.ctrl_mask));
Item3=new jmenuitem ("Copy", New ImageIcon ("Copy.gif"));
Item3.setaccelerator (Keystroke.getkeystroke (keyevent.vk_c,inputevent.ctrl_mask));
Item4=new JMenuItem ("Stop", New ImageIcon ("Stop.gif"));
Item4.setaccelerator (Keystroke.getkeystroke (keyevent.vk_t,inputevent.ctrl_mask));
Item5=new JMenuItem ("Refresh", New ImageIcon ("Snew.gif"));
Item5.setaccelerator (Keystroke.getkeystroke (keyevent.vk_n,inputevent.ctrl_mask));


Menu1.add (MENU4);
Menu4.add (New JMenuItem ("Open X", New ImageIcon ("Open.gif"));
Menu4.add (New JMenuItem ("Open y", New ImageIcon ("Open.gif"));
Menu1.addseparator ();
Menu1.add (ITEM2);
Menu2.add (ITEM3);
Menu3.add (ITEM4);
Menu3.add (ITEM5);

Menubar.add (MENU1);
Menubar.add (MENU2);
Menubar.add (MENU3);


Setjmenubar (menubar);
Validate ();
Setdefaultcloseoperation (Jframe.dispose_on_close);

}
}

Design of Windows application in Java

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.