GUI interface Programming--Notepad primary to achieve __ programming

Source: Internet
Author: User
GUI programming--Primary articles
I. Introduction to the ELEMENTS
1.JFrame class:

1 Concept: Its strength is called a window, belonging to the bottom of the container, you can directly interact with the operating system.

2) commonly used methods:

A.jframe () method to create an untitled window

B.jframe (Strings) method creates a window with the title s

C.public voidsetvisible (BOOLEANB) Settings window is visible

D.public void Dispose () to undo the current window, releasing resources

e.public void setdefaultcloseoperation (int operation) Setting the action that the program performs after clicking the Close button in the upper-right corner of the window

2.Jmenu class:

Concept: The JMenu class is responsible for creating menus.

3.JmenuItem class:

Concept: The JMenuItem class is responsible for creating an inline submenu. 4.JMenuBar class:

Concept: JMenuBar is a subclass of JFrame, JFrame has a method to place the menu bar in the window Setmenubar (jmenubarbar). two. Notepad code 1. Create Dialongdemo class and inherit JFrame.

Import java.awt.event.InputEvent;

Import javax.swing.*;


Import com.sun.glass.events.KeyEvent;
		public class Dialongdemo extends JFrame {//definition JMenuBar MenuBar;
		JMenu Menu1,menu2,menu3,menu4,menu5;
		JMenuItem Menu11,menu12,menu13,menu14,menu15,menu16,menu17;
		JMenuItem menu21,menu22,menu23,menu24,menu25,menu26,menu27,menu28,menu29,menu210,menu211;
		JMenuItem menu31,menu32;
		JMenuItem menu41;
		
		JMenuItem menu51,menu52;
			Public Dialongdemo () {//Empty construction Method}//The constructor of the parameter is public Dialongdemo (String s,int x,int y,int w,int h) {init (s);
			SetBounds (X,Y,W,H);
			SetVisible (TRUE); 
		Setdefaultcloseoperation (Jframe.dispose_on_close);
			The implementation of the//init method is public void init (String s) {settitle (s);
			MenuBar = new JMenuBar ();
			menu1 = new JMenu ("file");
			MENU2 = new JMenu ("edit");
			MENU3 = new JMenu ("format");
			Menu4 = new JMenu ("View");
			
			Menu5 = new JMenu ("help");
			Add the MenuBar component to the window Setjmenubar (MenuBar);
			Adding components such as menu1 to MenuBar Menubar.add (MENU1); MenubaR.add (MENU2);
			Menubar.add (MENU3);
			Menubar.add (MENU4);
			Menubar.add (MENU5);
			File Item Menu11 = new JMenuItem ("new");
			Menu12 = new JMenuItem ("open");
			Menu13 = new JMenuItem ("Save");
			MENU14 = new JMenuItem ("Save As");
			MENU15 = new JMenuItem ("Page Setup");
			Menu16 = new JMenuItem ("print");
			
			Menu17 = new JMenuItem ("Exit");
			Menu1.add (MENU11);
			Menu1.add (MENU12);
			Menu1.add (MENU13);
			Menu1.add (MENU14); 
			Menu1.addseparator ();
			Menu1.add (MENU15);
			Menu1.add (MENU16); 
			Menu1.addseparator ();
			
			Menu1.add (MENU17);
			Edit Item menu21 = new JMenuItem ("undo");
			Menu22 = new JMenuItem ("clip");
			Menu23 = new JMenuItem ("copy");
			menu24 = new JMenuItem ("paste");
			MENU25 = new JMenuItem ("delete");
			menu26 = new JMenuItem ("find");
			menu27 = new JMenuItem ("Find Next");
			MENU28 = new JMenuItem ("Replace");
			menu29 = new JMenuItem ("Go");
			menu210 = new JMenuItem ("Select All");
			
			menu211= New JMenuItem ("Time/Date");
			Menu2.add (MENU21);
			Menu2.addseparator ();
			Menu2.add (MENU22); Menu2. Add (Menu23);
			Menu2.add (MENU24);
			Menu2.add (MENU25);
			Menu2.addseparator ();
			Menu2.add (MENU26);
			Menu2.add (MENU27);
			Menu2.add (MENU28);
			Menu2.add (menu29);
			Menu2.addseparator ();
			Menu2.add (menu210);

			Menu2.add (menu211);
			Format menu31 = new JMenuItem ("Auto wrap");
			
			Menu32 = new JMenuItem ("Font");
			Menu3.add (MENU31);
			
			Menu3.add (MENU32);
			
			Status bar Menu41=new jmenuitem ("status bar");
			
			Menu4.add (MENU41);
			Help menu51 = new JMenuItem ("View Help");
			
			menu52 = new JMenuItem ("About Notepad");
			Menu5.add (menu51);
			Menu5.addseparator ();
			
			
			Menu5.add (menu52); 
			Set shortcut keys ctrl+* menu11.setaccelerator (Keystroke.getkeystroke (keyevent.vk_n,inputevent.ctrl_mask)); 
			Menu12.setaccelerator (Keystroke.getkeystroke (keyevent.vk_o,inputevent.ctrl_mask)); 
			Menu13.setaccelerator (Keystroke.getkeystroke (keyevent.vk_s,inputevent.ctrl_mask)); 

			Menu16.setaccelerator (Keystroke.getkeystroke (keyevent.vk_p,inputevent.ctrl_mask)); Menu21.setaccelerator (KeystroKe.getkeystroke (Keyevent.vk_z,inputevent.ctrl_mask)); 
			Menu22.setaccelerator (Keystroke.getkeystroke (keyevent.vk_x,inputevent.ctrl_mask)); 
			Menu23.setaccelerator (Keystroke.getkeystroke (keyevent.vk_c,inputevent.ctrl_mask));
			Menu24.setaccelerator (Keystroke.getkeystroke (keyevent.vk_v,inputevent.ctrl_mask));
			Menu25.setaccelerator (Keystroke.getkeystroke ("Del")); 
			Menu26.setaccelerator (Keystroke.getkeystroke (keyevent.vk_f,inputevent.ctrl_mask));
			Menu27.setaccelerator (Keystroke.getkeystroke ("F3")); 
			Menu28.setaccelerator (Keystroke.getkeystroke (keyevent.vk_h,inputevent.ctrl_mask)); 
			Menu29.setaccelerator (Keystroke.getkeystroke (keyevent.vk_g,inputevent.ctrl_mask));
			Menu210.setaccelerator (Keystroke.getkeystroke (keyevent.vk_v,inputevent.ctrl_mask));
			Menu211.setaccelerator (Keystroke.getkeystroke ("F5"));
			Text Object JTextArea area = new JTextArea (1065,570);
		Add (area);
 }
}

2. Create Main method main to implement

public class Main {public

	static void Main (string[] args) {
		//call with parameter constructor
		Dialongdemo dialongdemo=new Dialongdemo (new  text document, 100,100,1085,635);
		
	}



three. Results show:





Related Article

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.