Eclipse开发记事本程序

Eclipse开发记事本程序

ID:37913005

大小:39.00 KB

页数:3页

时间:2019-06-02

Eclipse开发记事本程序_第1页
Eclipse开发记事本程序_第2页
Eclipse开发记事本程序_第3页
资源描述:

《Eclipse开发记事本程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、Eclipse开发记事本程序1、新建项目,新建VisualClass,名称输入TextEditorApp,Style选Swing下的Frame,选中publicstaticvoidmain(String[]args),完成。2、进入JFrame中心面板,右击鼠标,设置中心面板的Layout为null布局。3、在palette的SwingContainers下选择jScrollPane,建立滚动面板,选择JtextArea建立多行文本,重命名为textArea。4、建立菜单栏jJMenuBar,插入四个菜单JMenu,分别改名为文件、编辑、工具、帮助;在“文件”下插入菜单项新建、打开、保

2、存、退出;在“编辑”下插入菜单项复制、剪切、粘贴、全选、颜色;在“工具”下插入菜单项计算器、记事本;在“帮助”插入菜单项关于。5、给“新建”菜单添加actionPerformed事件,在对应的代码处写入:textArea.setText(null);TextEditorApp.this.setTitle("无标题-记事本");6、给“打开”菜单添加actionPerformed事件,在对应的代码处写入:Filef1;JFileChooserjfc1=newJFileChooser();intnum1=jfc1.showOpenDialog(TextEditorApp.this);if(

3、num1==JFileChooser.APPROVE_OPTION){try{f1=jfc1.getSelectedFile();TextEditorApp.this.setTitle(f1.getName());FileReaderfr=newFileReader(f1);BufferedReaderbr=newBufferedReader(fr);Stringstr;while((str=br.readLine())!=null){textArea.setText(str);}fr.close();br.close();}catch(FileNotFoundExceptione1)

4、{e1.printStackTrace();}catch(IOExceptione2){e2.printStackTrace();}}7、给“保存”菜单添加actionPerformed事件,在对应的代码处写入:Filef2=null;JFileChooserjfc2=newJFileChooser();intnum2=jfc2.showSaveDialog(TextEditorApp.this);if(num2==JFileChooser.APPROVE_OPTION){f2=jfc2.getSelectedFile();TextEditorApp.this.setTitle(f2.

5、getName());try{FileWriterfw=newFileWriter(f2);BufferedWriterbw=newBufferedWriter(fw);bw.write(textArea.getText());bw.close();fw.close();}catch(IOExceptione2){e2.printStackTrace();}}8、给“退出”菜单添加actionPerformed事件,在对应的代码处写入:inta=JOptionPane.showConfirmDialog(TextEditorApp.this,"文件已被改变,是否要保存?","提示",J

6、OptionPane.YES_NO_CANCEL_OPTION);if(a==1){TextEditorApp.this.dispose();}elseif(a==0){Filef2=null;JFileChooserjfc2=newJFileChooser();intnum2=jfc2.showSaveDialog(TextEditorApp.this);if(num2==JFileChooser.APPROVE_OPTION){f2=jfc2.getSelectedFile();TextEditorApp.this.setTitle(f2.getName());try{FileWr

7、iterfw=newFileWriter(f2);BufferedWriterbw=newBufferedWriter(fw);bw.write(textArea.getText());bw.close();fw.close();}catch(IOExceptione2){e2.printStackTrace();}TextEditorApp.this.dispose();}}9、给“编辑”菜单中的复制、剪切、粘贴、全选添加actionPerf

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。