《记事本程序源代码汇总(共12页).doc》由会员分享,可在线阅读,更多相关《记事本程序源代码汇总(共12页).doc(12页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上import java.awt.event.*;import java.awt.*;import java.io.*;import java.lang.String;class jsb implements ActionListenerDialog bb;String strt;int i;FileDialog fd;File file;public Frame f;public TextArea p1;public MenuBar menubar;public Menu menu1,menu2,menu3;public MenuItem item1,item2,it
2、em3,item4,item5,item6,item7,item8,item9,item10; jsb(String s i=0;f=new Frame(s;p1=new TextArea(;f.setSize(500,500;f.setBackground(Color.white;f.setVisible(true;menubar=new MenuBar(;menu1=new Menu(文件;menu2=new Menu(编辑;menu3=new Menu(帮助;item1=new MenuItem(新建;item2=new MenuItem(打开;item3=new MenuItem(保存
3、;item4=new MenuItem(另存为;item5=new MenuItem(退出;item6=new MenuItem(全选;item7=new MenuItem(复制;item8=new MenuItem(剪切;item9=new MenuItem(粘贴;item10=new MenuItem(关于;f.addWindowListener(new WindowAdapter(public void windowClosing(WindowEvent ef.setVisible(false;System.exit(0;menu1.add(item1;menu1.add(item2;m
4、enu1.add(item3;menu1.add(item4;menu1.add(item5;menu2.add(item6;menu2.add(item7;menu2.add(item8;menu2.add(item9;menu3.add(item10;menubar.add(menu1;menubar.add(menu2;menubar.add(menu3;f.setMenuBar(menubar;item1.addActionListener(this;item2.addActionListener(this;item3.addActionListener(this;item4.addA
5、ctionListener(this;item5.addActionListener(this;item6.addActionListener(this;item7.addActionListener(this;item8.addActionListener(this;item9.addActionListener(this;item10.addActionListener(this;f.setLayout(new GridLayout(1,1;f.add(p1;f.pack(;public void actionPerformed(ActionEvent e String ss;ss=p1.
6、getText(.trim(;if (e.getSource(=item5if (i=0 &(ss.length(!=0bc(;elseSystem.exit(0;if (e.getSource(=item1if (i=0&(ss.length(!=0bc(;elsep1.setText(;i=0;f.setTitle(文件对话框; if (e.getSource(=item2fd=new FileDialog(f,打开文件,0;fd.setVisible(true;tryfile=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getF
7、ile(+文件对话框; FileReader fr=new FileReader(file; BufferedReader br=new BufferedReader(fr; String line = null;String view = ;while(line=br.readLine(!=nullview += line+n;p1.setText(view;br.close(;fr.close(;catch(IOException expInif (e.getSource(=item3if (i=0bc(;elsetryfile=new File(fd.getDirectory(,fd.g
8、etFile(;f.setTitle(fd.getFile(+-记事本;FileWriter fw=new FileWriter(file; BufferedWriter bw=new BufferedWriter(fw; String s =p1.getText(;s = s.replaceAll(n,rn;bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;catch(IOException expOuti=0;if (e.getSource(=item4bc(;if (e.getSource(=item10bb=new Dialog(f,关于;Lab
9、el l1=new Label(本记事本的完成感谢老师和同学的帮助!; bb.add(l1;bb.setSize(250,150;bb.setBackground(Color.white;bb.show(;bb.addWindowListener(new WindowAdapter(public void windowClosing(WindowEvent ebb.setVisible(false;bb.dispose(;if (e.getSource(=item6p1.setSelectionStart(0;p1.setSelectionEnd(p1.getText(.length(;if
10、(e.getSource(=item7tryString str=p1.getSelectedText(;if(str.length(!=0strt=str;catch(Exception exif (e.getSource(=item8tryString str=p1.getSelectedText(;if(str.length(!=0p1.replaceRange(,p1.getSelectionStart(,p1.getSelectionEnd(; catch(Exception exif (e.getSource(=item9if(strt.length(0p1.insert(strt
11、,p1.getCaretPosition(;public void bc(fd=new FileDialog(f,保存文件,1;fd.setVisible(true;tryfile=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+-记事本;FileWriter fw=new FileWriter(file;BufferedWriter bw=new BufferedWriter(fw;String s =p1.getText(;s = s.replaceAll(n,rn;bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;catch(IOException expOut public class EX0101 public static void main(String args jsb dd=new jsb(我的记事本; 专心-专注-专业