eclipse开发记事本程序

上传人:第*** 文档编号:38772788 上传时间:2018-05-07 格式:DOC 页数:3 大小:39KB
返回 下载 相关 举报
eclipse开发记事本程序_第1页
第1页 / 共3页
eclipse开发记事本程序_第2页
第2页 / 共3页
eclipse开发记事本程序_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《eclipse开发记事本程序》由会员分享,可在线阅读,更多相关《eclipse开发记事本程序(3页珍藏版)》请在金锄头文库上搜索。

1、EclipseEclipse 开发记事本程序开发记事本程序1、新建项目,新建 Visual Class,名称输入 TextEditorApp,Style 选Swing 下的 Frame,选中 public static void main(String args),完成。2、进入 JFrame 中心面板,右击鼠标,设置中心面板的 Layout 为 null 布局。3、在 palette 的 Swing Containers 下选择 jScrollPane,建立滚动面板,选择 JtextArea 建立多行文本,重命名为 textArea。4、建立菜单栏 jJMenuBar,插入四个菜单 JMen

2、u,分别改名为文件、编辑、工具、帮助;在“文件”下插入菜单项新建、打开、保存、退出;在“编辑”下插入菜单项复制、剪切、粘贴、全选、颜色;在“工具”下插入菜单项计算器、记事本;在“帮助”插入菜单项关于。5、给“新建”菜单添加 actionPerformed 事件,在对应的代码处写入:textArea.setText(null); TextEditorApp.this.setTitle(“无标题 - 记事本“);6、给“打开”菜单添加 actionPerformed 事件,在对应的代码处写入:File f1; JFileChooser jfc1 = newnew JFileChooser(); i

3、ntint num1 = jfc1.showOpenDialog(TextEditorApp.thisthis); ifif(num1=JFileChooser.APPROVE_OPTION) trytry f1 = jfc1.getSelectedFile(); TextEditorApp.thisthis.setTitle(f1.getName(); FileReader fr = newnew FileReader(f1); BufferedReader br = newnew BufferedReader(fr); String str; whilewhile(str = br.rea

4、dLine()!=nullnull) textArea.setText(str); fr.close(); br.close(); catchcatch(FileNotFoundException e1) e1.printStackTrace(); catchcatch(IOException e2) e2.printStackTrace(); 7、给“保存”菜单添加 actionPerformed 事件,在对应的代码处写入:File f2 = nullnull; JFileChooser jfc2 = newnew JFileChooser(); intint num2 = jfc2.sho

5、wSaveDialog(TextEditorApp.thisthis); ifif(num2=JFileChooser.APPROVE_OPTION) f2=jfc2.getSelectedFile(); TextEditorApp.thisthis.setTitle(f2.getName(); trytry FileWriter fw = newnew FileWriter(f2); BufferedWriter bw = newnew BufferedWriter(fw); bw.write(textArea.getText(); bw.close(); fw.close(); catch

6、catch(IOException e2) e2.printStackTrace(); 8、给“退出”菜单添加 actionPerformed 事件,在对应的代码处写入:intint a = JOptionPane.showConfirmDialog(TextEditorApp.thisthis,“文件已被改变,是否要保存?“,“提示“,JOptionPane.YES_NO_CANCEL_OPTION); ifif(a=1) TextEditorApp.thisthis.dispose(); elseelse ifif(a=0) File f2 = nullnull; JFileChooser

7、 jfc2 = newnew JFileChooser(); intint num2 = jfc2.showSaveDialog(TextEditorApp.thisthis); ifif(num2=JFileChooser.APPROVE_OPTION) f2=jfc2.getSelectedFile(); TextEditorApp.thisthis.setTitle(f2.getName(); trytry FileWriter fw = newnew FileWriter(f2); BufferedWriter bw = newnew BufferedWriter(fw); bw.wr

8、ite(textArea.getText(); bw.close(); fw.close(); catchcatch(IOException e2) e2.printStackTrace(); TextEditorApp.thisthis.dispose(); 9、给“编辑”菜单中的复制、剪切、粘贴、全选添加 actionPerformed 事件,在对应的代码处分别写入:textArea.copy();textArea.cut();textArea.paste();textArea.selectAll();10、给“颜色”菜单添加 actionPerformed 事件,在对应的代码处写入:Co

9、lor color=JColorChooser.showDialog(textArea, “选择颜色“, Color.BLACK);textArea.setForeground(color);11、给“记事本”菜单添加 actionPerformed 事件,在对应的代码处写入:trytryString command = “notepad.exe“;Process child = Runtime.getRuntime().exec(command);catchcatch (IOException ex) 12、给“计算器”菜单添加 actionPerformed 事件,在对应的代码处写入:tr

10、ytryString command = “calc.exe“;Process child = Runtime.getRuntime().exec(command);catchcatch (IOException ex)13、给“关于”菜单添加 actionPerformed 事件,在对应的代码处写入:String message = “-n版本:1.0n作者:刘艳慧“ + “nn感谢您的使用!“;JOptionPane.showMessageDialog(TextEditorApp.thisthis, message, “关于“, JOptionPane.PLAIN_MESSAGE); 注意:不能识别的文件需导入包,在错误处单击,选择需导入的包文件,双击引入。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号