您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > java记事本源代码
importjava.awt.*;importjava.awt.event.*;importjava.io.*;importjava.util.*;importjavax.swing.*;publicclassnote{publicstaticvoidmain(String[]args){myfrfr=newmyfr(JAVA¼Çʱ¾);fr.setSize(560,395);}}///////////////////////////myfrÖ÷´°ÌåÀà//////////////////////////////////////classmyfrextendsJFrameimplementsActionListener{Stringstr,strnext,path,fname;//²¿·Ö±äÁ¿µÄÉùÃ÷JPanelmainpane;JFileChooserchoose=newJFileChooser();//Îļþ¶Ô»°¿òDialogfind,replace;//findΪ²éÕÒ¶Ô»°¿ò£¬replace¶Ô»°¿òJTextFieldfindtxt,repltxt;//findtxtΪ²éÕÒ¶Ô»°¿òµÄÊäÈëÎı¾Çø£¬repltxt¶Ô»°¿òµÄÊäÈëÎı¾ÇøFontnewfont;JButtonfindenter,replb;//findΪ²éÕÒ¶Ô»°¿ò£¬replace¶Ô»°¿òµÄÈ·¶¨°´Å¥JLabelstate=newJLabel(JAVA¼Çʱ¾------δÃüÃûÎĵµ);//״̬À¸JTextAreatxt1;//Ö÷ÊäÈëÎı¾ÇøFilenewfiles;JPopupMenupopm;//µ¯³ö²Ëµ¥ÉùÃ÷//JMenum1,m2,m3,m4,m5,m6;//¸÷²Ëµ¥ÏîJMenum1,m2,m3;JMenuItemm26,m271,m34,p_copy,p_cut,p_paste,p_del;//JMenuItemm26,m271,p_copy,p_cut,p_paste,p_del;intstartp,endp,nexttemp,newstartp,newendp;//²éÕÒÌ滻ʱËùÓõÄÁÙʱ±äÁ¿JToolBartoolbar=newJToolBar();//¹¤¾ßÌõJButtonnewf=newJButton(newImageIcon(pic/new.gif));//ͼ±êÔÚPICÏÂJButtonopen=newJButton(newImageIcon(pic/open.gif));JButtonsave=newJButton(newImageIcon(pic/save.gif));JButtoncopy=newJButton(newImageIcon(pic/copy.gif));JButtoncut=newJButton(newImageIcon(pic/cut.gif));JButtonpp=newJButton(newImageIcon(pic/pp.gif));JButtondel=newJButton(newImageIcon(pic/del.gif));JButtonfindc=newJButton(newImageIcon(pic/find.gif));JButtoncount=newJButton(newImageIcon(pic/count.gif));//JButtoncolor=newJButton(newImageIcon(pic/color.gif));myfr(Stringsss)/////¹¹Ô캯Êý¿ªÊ¼{super(sss);JMenuBarmb=newJMenuBar();fname=null;//³õʼÎļþÃûΪ¿Õfindenter=newJButton(È·¶¨);//findΪ²éÕÒ¶Ô»°¿ò£¬replace¶Ô»°¿òµÄÈ·¶¨°´Å¥findenter.addActionListener(this);//ÉùÃ÷¶Ô»°¿òÖÐÉÏÈ·¶¨°´Å¥£¬²¢×¢²áʼþreplb=newJButton(È·¶¨);//replace¶Ô»°¿òµÄÈ·¶¨°´Å¥replb.addActionListener(this);mainpane=(JPanel)this.getContentPane();mainpane.setLayout(newBorderLayout());txt1=newJTextArea(,13,61);txt1.addMouseListener(newhandlemouse(this));//×¢²áÊó±êÓÒ»÷ʼþtxt1.setFont(newFont(ËÎÌå,Font.PLAIN,18));mainpane.add(txt1,BorderLayout.CENTER);mainpane.add(North,toolbar);mainpane.add(South,state);JScrollPanesll=newJScrollPane();//´´½¨¹ö¶¯Ìõmainpane.add(Center,sll);;sll.getViewport().add(txt1);//½«¹ö¶¯Ìõ×°ÈëÎı¾Çøpopm=newJPopupMenu();////POPMeun¿ªÊ¼p_copy=newJMenuItem(¸´ÖÆ);p_copy.addActionListener(this);KeyStrokekeycopyp=KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK);p_copy.setAccelerator(keycopyp);p_cut=newJMenuItem(¼ôÇÐ);p_cut.addActionListener(this);KeyStrokekeycutp=KeyStroke.getKeyStroke(KeyEvent.VK_X,Event.CTRL_MASK);p_cut.setAccelerator(keycutp);p_paste=newJMenuItem(Õ³Ìù);p_paste.addActionListener(this);KeyStrokekeypp=KeyStroke.getKeyStroke(KeyEvent.VK_V,Event.CTRL_MASK);p_paste.setAccelerator(keypp);p_del=newJMenuItem(ɾ³ý);p_del.addActionListener(this);KeyStrokekeydelp=KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0);p_del.setAccelerator(keydelp);popm.add(p_copy);popm.add(p_cut);popm.add(p_paste);popm.add(p_del);txt1.add(popm);////POPMenu½áÊøm1=newJMenu(Îļþ(F));m1.setMnemonic('F');//¶¨Òå¿ì½Ý·½Ê½JMenuItemm10=newJMenuItem(н¨);m10.addActionListener(this);//×¢²áʼþ¼àÌýÆ÷KeyStrokekeynew=KeyStroke.getKeyStroke(KeyEvent.VK_N,Event.CTRL_MASK);//¶¨Òå¿ì½Ý¼üm10.setAccelerator(keynew);JMenuItemm11=newJMenuItem(´ò¿ª);m11.addActionListener(this);KeyStrokekeyopen=KeyStroke.getKeyStroke(KeyEvent.VK_O,Event.CTRL_MASK);m11.setAccelerator(keyopen);JMenuItemm12=newJMenuItem(±£´æ);m12.addActionListener(this);KeyStrokekeysave=KeyStroke.getKeyStroke(KeyEvent.VK_S,Event.CTRL_MASK);m12.setAccelerator(keysave);JMenuItemm13=newJMenuItem(Áí±£´æΪ);m13.addActionListener(this);JMenuItemm14=newJMenuItem(Í˳ö);m14.addActionListener(this);KeyStrokekeyexit=KeyStroke.getKeyStroke(KeyEvent.VK_F4,Event.ALT_MASK);m14.setAccelerator(keyexit);////////////////////////////////////////////m2=newJMenu(±à¼(E));m2.setMnemonic('E');JMenuItemm21=newJMenuItem(¸´ÖÆ);m21.addActionListener(this);KeyStrokekeycopy=KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK);m21.setAccelerator(keycopy);JMenuItemm22=newJMenuItem(¼ôÇÐ);m22.addActionListener(this);KeyStrokekeycut=KeyStroke.getKeyStroke(KeyEvent.VK_X,Event.CTRL_MASK);m22.setAccelerator(keycut);JMenuItemm23=newJMenuItem(Õ³Ìù);m23.addActionListener(this);KeyStrokekeyp=KeyStroke.getKeyStroke(KeyEvent.VK_V,Event.CTRL_MASK);m23.setAccelerator(keyp);JMenuItemm24=newJMenuItem(ɾ³ý);m24.addActionListener(this);KeyStrokekeydel=KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0);m24.setAccelerator(keydel);JMenuItemm25=newJMenuItem(²éÕÒ);m25.addActionListener(this);KeyStrokekeyfind=KeyStroke.getKeyStroke(KeyEvent.VK_F,Event.CTRL_MASK);m25.setAccelerator(keyfind);m26=newJMenuItem(²éÕÒÏÂÒ»¸ö);m26.addActionListener(this);KeyStrokekeyfn=KeyStroke.getKeyStroke(KeyEvent.VK_F3,0);m26.setAccelerator(keyfn);m26.setEnabled(false);JMenuItemm27=newJMenuItem(Ìæ»»);m27.addActionListener(this);KeyStrokekeyrepl=KeyStroke.getKeyStroke(KeyEvent.VK_H,Event.CTRL_MASK);m27.setAccelerator(keyrepl);m271=new
本文标题:java记事本源代码
链接地址:https://www.777doc.com/doc-4376473 .html