A notepad demo

Source: Internet
Author: User

Import java. AWT. checkboxmenuitem;
Import java. AWT. frame;
Import java. AWT. Menu;
Import java. AWT. menubar;
Import java. AWT. menuitem;
Import java. AWT. menushortcut;
Import java. AWT. textarea;
Import java. AWT. event. actionevent;
Import java. AWT. event. actionlistener;
Import java. AWT. event. keyevent;
Import java. AWT. event. windowadapter;
Import java. AWT. event. javaswevent;


Public class notepad {
Private frame F = new frame ("Notepad ");
Private menubar MB = new menubar ();
Menu file = new menu ("file ");
Menu edit = new menu ("edit ");
Menuitem newitem = new menuitem ("new ");
Menuitem saveitem = new menuitem ("save ");
Menuitem exititem = new menuitem ("exit", new menushortcut (keyevent. vk_x ));
Checkboxmenuitem autowrap = new checkboxmenuitem (" ");
Menuitem copyitem = new menuitem ("copy ");
Menuitem pasteitem = new menuitem ("Paste ");
Menu format = new menu ("format ");
Menuitem commentitem = new menuitem ("comment", new menushortcut (keyevent. vk_slash, true ));
Menuitem cancelitem = new menuitem ("uncomment ");
Private textarea TA = new textarea (6, 40 );
 
Public void Init ()
{
// Create a menu listener for an anonymous internal class
Actionlistener menulistener = new actionlistener ()
{
Public void actionreceivmed (actionevent E)
{
String cmd = E. getactioncommand ();
Ta. append ("click" + cmd + "" menu "+" \ n ");
If (CMD. Equals ("quit "))
{
System. Exit (0 );
}
}
};
// Add an event listener for the commentitem menu
Commentitem. addactionlistener (menulistener );
Exititem. addactionlistener (menulistener );
File. Add (newitem );
File. Add (saveitem );
File. Add (exititem );
Edit. Add (autowrap );
Edit. addseparator ();
Edit. Add (copyitem );
Edit. Add (pasteitem );
Format. Add (commentitem );
Format. Add (cancelitem );
Edit. Add (New menuitem ("-"));
Edit. Add (format );
MB. Add (File );
MB. Add (edit );
F. setmenubar (MB );
// Create a listener object for the anonymous internal class
F. addwindowlistener (New windowadapter ()
{
Public void windowclosing (windowevent E)
{
System. Exit (0 );
}
});
F. Add (TA );
F. Pack ();
F. setvisible (true );
}
Public static void main (string [] ARGs)
{
New notepad (). INIT ();
}
}

A notepad demo

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.