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