版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Java课程设计报告题目:班级:学号:姓名:成绩:文本编辑器日期:一、综合设计的目的与要求 3二、综合设计正文31 .系统分析 31.1 系统开发背景、开发范围、建设目标与必要性开发31.2 需求分析 32 .系统设计 32.1 功能设it 32.2 系统运行环境与开发工具 43 .系统实施 43.1 源程序 43.2 .系统测试及部分截图 12三、综合设计总结或结论 13文本编辑器一、综合设计的目的与要求要求在学生能够较熟练使用 java程序设计语言进行软件代码的编写,同时还要具备较好的项目分析的能力,加深对相关课程基本内容的理解。同时,在程序设计方法以及 上机操作等基本技能和科学作风方面受
2、到比较系统的练习。二、综合设计正文1系统分析1.1 系统开发背景、开发范围、建设目标与必要性随着计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的 各个领域并发挥着越来越重要的作用。当然对文本编辑操作仍然占据着重要地位,记事 本是简单便捷的文本编辑器,可实现对文本编辑操作的基本功能。1.2 需求分析程序设计主要分为两大部分:简单GUI设计和程序功能设计。 通过GUI设计实现图形用户界面,提供图形菜单,方便用户操作。使用Java语言编写一个能够对输入文字进行操作,具有合理的界面, 能够在界面中实现右键快捷方式,对文档内容进行编辑操作,并且能够顺利退出的程序。通过设计和实现一个具
3、有基本功能的文本编辑器,提高我们对Java语言设计的掌握能力,理论联系实际,进一步提高软件开发技术,从而培 养我们分析、解决问题的能力。2系统设计1.1 功能设计根据系统自带的文档编辑器的特征设计,包括如下的功能模块:一、整体结构框架包括:菜单栏和文档编辑区二、每个框架分别包含不同的子框架,各个模块的具体框架:1 .菜单栏:文件、编辑、工具、帮助2 .菜单栏中各个子菜单功能文件:新建、打开、保存、另存为、退出编辑:剪切、复制、粘贴工具:查找、替换3 .子菜单功能的实现主要的几个功能介绍171) 打开与另存为:两个窗体调用系统函数直接利用,注意格式的选择2) 查找:查找内容、查找、查找下一个4
4、.文本编辑区监视文本内容是否改变、监听光标所在位置2.2系统运行环境与开发工具开发环境与工具:jdk2.0 Eclipse SDK3系统实施3.1 源程序import javax.swing.*;import java.awt.*;import java.io.*;import java.awt.event.*;public class TxtEditor extends J Fra me imple ments ActionLis tenerString file _n a me;String file_dir;String tempString;/上次保存后的文件名和地址String Hl
5、eName =JPanel x=new JPanel();J Text Are a we n=new JTextArea(20,50);J Menuitem ziti=new JMenuItem(M 字体”);J Menuitem a=ne w J MenuItem(M普通”);/定义菜单项J Menuitem xin=new JMenuItem(M新建”);J Menuitem open=new JMenuItem(H打开”);J Menuitem save=new JMenuItem(n保存);J Menuitem lsave=new J Menultem(,r 另存为);J Menuit
6、em tui=new JMenuItem(n退出”);J Menuitem cut=new JMenuItem(n 剪切”);J Menuitem copy=ne w JMenuItem(H 复制”);J Menuitem cast=new JMenuItem(H 粘贴”);J Menuitem delete=new JMenultem(n 删除”);JMenuitem b=new JMenuItem(M粗体”);J Menuitem c=new J Menultem(,r斜体”);TxtEditor()super (H文本编辑器”);/对话框selBounds(250,100,700,450
7、);setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);addWindowListener(ne w WindowAdapter()public void windowClosing(WmdowEvent e) int option= JOptionPane.showConfirmDialog(TxtEditor.this,”确定要退出吗 ,”系统和你对话M,J OptionPane. YES.NO.OPTION);if(option=J OptionPane. YES .OPTION) if(e.getWindow() = TxtEditor.this
8、) (Syste m.exit(0);) else( return;);/热键设置xin.se t Acce le ra tor(Ke yS troke .ge tKe yS troke (Ke yE ve nt. VK_N, ActionEve nt.CTRL_MAS K);open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,ActionEvent.CTRL_MAS K);save.setAccelerator(KeyStroke.getKeyS troke (Ke yEve nt. VK_S, ActionEve nt.CTRL
9、_MAS K);cut.setAcce le rator(Ke yS troke .ge tKeyS troke (Ke yEve nt. VK_X, ActionEve nt.CTRL_MAS K);copy.se tAccelerator(KeyS troke.ge tKe yS troke (Ke yEve nt. VK_C, ActionEve nt.CTRL_MAS K);cast.se t Acce le ra tor(Ke yS troke .ge tKe yS troke (Ke yEve nt.VK_V,ActionEvent.CTRL_MAS K);/定义面板/ x.add
10、(add(new JScrollPane (wen);/);/ 滚动条wen.setFont(new Font(,r楷体 ”,Font.PLAIN ,20);/ wen.setBackground(Color.blue);/ add(x);/ 菜单栏的创建J MenuBar cai=new J MenuBar();this.setJ Me nuBar(cai);cai.setOpaque(true);JMenu jian=new J Menu( 文件);jian.add(xin);jian.add(open);jian.add(save);jian.add(lsave);jian.addSep
11、arator();jian.add(tui);cai.add(jian);J Menu bian= new JMenu( 编辑);bian.add(cut);bian.add(copy);bian.add(cast);bian.add(delete);cai.add(bian);J Menu geshi = new J Menu (n 格式”);J Menu optionsMenu=new JMenu(M 字体”); geshi.add(optionsMe nu);options Menu.add(a);options Menu.add(b);options Menu.add(c); cai.
12、add(geshi);/增加监听器xin.addActionLis tener(this);open.addActionListener(this);save.addActionLis tener(this);Isave.addActionListener(this);tui.addActionListener(this);cut.addActionLis te ner(this);copy.addActionListener(this);cast.addActionListener(this);dele te.addActionLis tener(this);ziti.add Actio n
13、 Lis te n e r(th is);a.addActionLis tener(this);b.addActionLis tener(this);c.addActionLis te ner(this);/文本框锁定/th is.se tRe s izab le(false);/重写方法public void actionPerfbrmed(ActionEvent e)(String actionCommand=e.getActionCommand(); if(e .ge tS ource ()ins ta nee of J Me nu);(ifi(e.getSource()=xin)ne
14、wlile();Ielse if(e.getSource()=open) openfile();)else ife.getSource()=save)save iile();Ielse if(e.getSource()=lsave)IsavefileO;Ielse ifife.getSource()=cut) cutfile ();)else if(e.getSource()=copy) copyfile ();)else if(e.getSource()=cast) castfile();)else if(e.getSource()=delete)(dele te file();Ielse
15、if(e.getSource()=a)a file ();)else ifi(e.getSource()=b)bfile();Ielse ifi(e.getSource()=c)cfile();)else if(M 退出 H.equaIs(actionCommand)System.exit(O);/ 方法定义public void ne wfile()save file();wen.setText(null);file Na me = ,n;)/ 打开public void open file ()String file Na me = null;File Dia log df= new Fi
16、le Dia log (th is;打开文件 :File Dia log.LOAD);df.setVis ible(true);/建立新文件File f = new File( df.getDirectory()+df.getFile();/得到文件名file Na me = df.getDirectory()+df.getFile();/用此文件的长度建立一个字符数组(特别标注)char ch = new char |(int)f.length()J;/异常处理try(/读出数据,并存入字符数组 ch中BufieredReader bw = new BufferedReader( new F
17、ile Re a de r(f);bw.read(ch);bw.close();)catch( FileNotFoundException fe )System.out.println(nfile not foundM);System.exit(O);)catch( lOException ie) System.out.println(HlO error11); System.exit(O);String s =new String (ch);wen.setTe xt(s);)/保存public void savefile()if( file Na me.equals。)File Dia lo
18、gdf = newFile Dia log (th is,M,File Dia log.SAVE);df.addWindowListener( new WindowAdapter() public void windowClosing(WiiidowEvent ee)System.exit(O););df.setVis ible(lrue);String s = wen.getText();try(File f = new File( df.getDiiectory()+df.getFile();new File Writer );file Na me = d f.ge tDire ctory
19、()+d f.ge tFile ();BufferedWriter bw = new Buffered Write r( bw.write(s , 0 , s.length();bw.close();)catch(FileNotFoundException fe_)System.out.println(ulile not found1); System.exit(O);)catch( lOException ie_)(System.out.println(n IO errorM);System.exit(O);)/如果文件已经保存过else(String s = wen.getText();t
20、ryFile f = new File( fileName );BufferedWriter bw = new BufferedWriter( new File Writer );bw.write(s , 0 , s.length();bw.close();)catch(FileNotFoundException fe_)System.out.println(Hfile not foundM);System.exit(O);)catch( lOException ie_)(System.out.println(H IO error11);System.exit(O);)1/ 另存为public
21、 void Is a ve file () File Dia log df= new File Dia log (this;1 另存为,FUe Dia log.SAVE);df.addWindowListener( new WindowAdapter()public void windowClosing(WindowEvent ee)Syste m.exit(O););df.setVis ible(true);String s = wen.getText();try(File f = new File( df.getDirectory()+df.getFile();Buffered Write
22、r bw = new Buffered Write r( new File Writer (0);bw.write(s , 0 , s.length();bw.close();)catch(FileNotFoundException 佗_)S ys te m. o u t. print In (nlile not foundM);Syste m.exit(O);)catch( lOException ie_) (System.out.println(H IO error);Syste m.exit(O);)/ 剪切public void cutfile()tempS (ring = wen.g
23、etSelectedText();StringBuffer Imp = new StringBuffer ( wen.getText();int start = we n.getS e lectionS tart();int len = wen.getSelectedText().length();tmp.delete( start , start+len);wen.setTe xt(tmp.toStringO);I/复制public void copyflle()te mp String = wen.getSelectedText();I/粘贴public void castfile()St
24、ringBuffer Imp = new StringBuffer ( wen.getText();/得到要粘贴的位置int start = wen.getSelectionStart();tmp.insert(start , tempString);/ 用新文本设置原文本wen.setText(tmp.toStringO);)/ 删除public void deletefile()StringBuffer tmp = new StringBuffer ( wen.getText();int start = wen.getSeleclionStart();int len = wen.getSelectedText().length();tmp.delete( start, start+len);wen.setText(tmp.toStringO);I/字体public void afile()wen.setFont(new Font( 楷体,Font.PLAIN ,wen.getFont().getSize();/ 普通文字public void bfile()wen.setFont(new Font(n 楷体 ,Font.BOLD ,wen.getFont().getSi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度个人失业保险合同规范范本4篇
- 易错点15 气体状态变化引起的内能改变问题 (5陷阱点4考点4题型)2025版高考物理易错点透析讲义(含答案)
- 课题申报参考:民族地区旅居养老场域中的文化互动与族群认同
- 统编版二年级下册语文《古诗二首》 课件完整版
- 生物控制在病虫害防治中的应用
- 2025年度人工智能技术研发个人劳务合同书3篇
- 二零二五年度场项目投标失败原因调查与改进策略合同4篇
- 2025年房屋赠与合同模板
- 2025年分期付款影视制作合同
- 2025年度钢材出口退税代理服务合同样本2篇
- 2024-2025学年山东省潍坊市高一上册1月期末考试数学检测试题(附解析)
- 江苏省扬州市蒋王小学2023~2024年五年级上学期英语期末试卷(含答案无听力原文无音频)
- 数学-湖南省新高考教学教研联盟(长郡二十校联盟)2024-2025学年2025届高三上学期第一次预热演练试题和答案
- 决胜中层:中层管理者的九项修炼-记录
- 幼儿园人民币启蒙教育方案
- 军事理论(2024年版)学习通超星期末考试答案章节答案2024年
- 《无人机法律法规知识》课件-第1章 民用航空法概述
- 移动商务内容运营(吴洪贵)任务七 裂变传播
- 单级倒立摆系统建模与控制器设计
- 龋病的治疗 深龋的治疗
- 银行卡冻结怎么写申请书
评论
0/150
提交评论