已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
算算法法与与数数据据结结构构 课课程程设设计计报报告告书书 信息科学与技术学院信息科学与技术学院 问题描述 问题描述 课题课题 17 17 设计一个简单的文本编辑器 使其具有通常编辑器 如设计一个简单的文本编辑器 使其具有通常编辑器 如 NotepadNotepad 具备的功能 具备的功能 1 设计的软 硬件环境 设计的软 硬件环境 系系 统 统 WindowsWindows 7 7 内存 内存 4G4G cpucpu corecore i3i3 380M380M 2 532 53 GhzGhz 运行环境 运行环境 JDKJDK 1 61 6 编译软件 编译软件 eclipseeclipse ADT ADT 数据结构与算法数据结构与算法 设计与功能模块 设计与功能模块 MenuMenu mbmb newnew MenuBar MenuBar MenuMenu m1m1 newnew Menu Menu FileFile NewNew OpenOpen SavaSava ExitExit SaveAs SaveAs 新建 打开 保存 退出 另存为新建 打开 保存 退出 另存为 MenuMenu m2m2 newnew Menu Menu EditEdit CutCut CopyCopy PastePaste 剪切 复制 粘贴剪切 复制 粘贴 MenuMenu m3m3 newnew Menu Menu FormatFormat Font Font 字体字体 LowLow toto Captital Captital 小写转大写小写转大写 CaptitalCaptital toto Low Low 大写转小写大写转小写 MenuMenu m4m4 newnew Menu Menu HelpHelp Help Help 版本信息版本信息 2 正文 宋体 小四 行间距固定值 22 磅 图表中的文本为宋体 5 号 行间距固定值 12 磅 3 4 5 6 7 实验结果分析及收获 实验结果分析及收获 通过这次课程设计让我理解图形界面的开发 收获挺多通过这次课程设计让我理解图形界面的开发 收获挺多 附录 源程序清单 附录 源程序清单 packagepackage demo1 demo1 importimport java awt java awt importimport java awt event java awt event importimport java io java io publicpublic classclass test1test1 privateprivate intint id font id font 字体字体 privateprivate staticstatic StringString tempString tempString 临时字符串 用于存储需要复制粘贴的字符串临时字符串 用于存储需要复制粘贴的字符串 24 staticstatic StringString filename filename 文件名文件名 param param argsargs publicpublic staticstatic voidvoid main String main String args args TODOTODO Auto generatedAuto generated methodmethod stubstub finalfinal FrameFrame f f newnew Frame Frame 记事本记事本 f setSize 600 400 f setSize 600 400 f setLocation 100 100 f setLocation 100 100 TextField TextField tftf newnew TextField 20 TextField 20 f add tf North f add tf North finalfinal TextAreaTextArea tftf newnew TextArea TextArea f add tf f add tf tf setBackground newtf setBackground new ColorColor 50 50 250 200 250 200 f addWindowListener newf addWindowListener new WindowAdapter WindowAdapter publicpublic voidvoid windowClosing WindowEventwindowClosing WindowEvent e e System exit 0 System exit 0 MenuBarMenuBar mbmb newnew MenuBar MenuBar MenuMenu m1m1 newnew Menu Menu 文件文件 1 MenuMenu m2m2 newnew Menu Menu 编辑编辑 MenuMenu m3m3 newnew Menu Menu 格式格式 MenuMenu m4m4 newnew Menu Menu 帮助帮助 MenuItemMenuItem mi1 mi1 newnew MenuItem MenuItem 新建新建 mi1 addActionListener newmi1 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e tf replaceRange 0 tf replaceRange 0 tf getText length tf getText length StringString strFile strFile 文件名清空文件名清空 MenuItemMenuItem mi2 mi2 newnew MenuItem MenuItem 打开打开 mi2 addActionListener newmi2 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e 注册监听器注册监听器 FileDialogFileDialog d d newnew FileDialog f openFileDialog f open file FileDialog LOAD file FileDialog LOAD 创建文件对话框创建文件对话框 打开文件对话框打开文件对话框 d addWindowListener newd addWindowListener new WindowAdapter WindowAdapter publicpublic voidvoid windowClosing WindowEventwindowClosing WindowEvent ee ee System exit 0 System exit 0 1 d setVisible true d setVisible true FileFile f f newnew File d getDirectory d getFile File d getDirectory d getFile 建立新文件建立新文件 StringString strfile strfile d getDirectory d getFile d getDirectory d getFile 得到文件名得到文件名 charchar ch newch new charchar int f length int f length 用此文件的长度建立一个字符数组用此文件的长度建立一个字符数组 try try 异常处理异常处理 读出数据 并存入字符数组读出数据 并存入字符数组 chch 中中 BufferedReaderBufferedReader bwbw newnew BufferedReader BufferedReader newnew FileReader f FileReader f bw read ch bw read ch bw close bw close catch FileNotFoundExceptioncatch FileNotFoundException fe fe System out println fileSystem out println file notnot found found System exit 0 System exit 0 catch IOExceptioncatch IOException ie ie System out println IOSystem out println IO error error System exit 0 System exit 0 StringString s news new String ch String ch tf setText s tf setText s 1 MenuItemMenuItem mi3 mi3 newnew MenuItem MenuItem 保存保存 mi3 addActionListener newmi3 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e if filename equals if filename equals 如果文件没有被保存过 即文件名为空如果文件没有被保存过 即文件名为空 FileDialogFileDialog d newd new FileDialog f saveFileDialog f save file FileDialog SAVE file FileDialog SAVE 保存文件对话框保存文件对话框 d addWindowListener newd addWindowListener new WindowAdapter WindowAdapter 关闭文件对话框窗口关闭文件对话框窗口 publicpublic voidvoid windowClosing WindowEventwindowClosing WindowEvent ee ee System exit 0 System exit 0 d setVisible true d setVisible true StringString s s tf getText tf getText 得到所输入的文本内容得到所输入的文本内容 try try 异常处理异常处理 FileFile f f newnew File d getDirectory d getFile File d getDirectory d getFile 新建文件新建文件 1 StringString strfilestrfile d getDirectory d getFile d getDirectory d getFile 得到文件名得到文件名 BufferedWriterBufferedWriter bwbw newnew BufferedWriter newBufferedWriter new FileWriterFileWriter f f 输入到文件中输入到文件中 bw write s 0 s length bw write s 0 s length bw close bw close catch FileNotFoundExceptioncatch FileNotFoundException fe fe System out println fileSystem out println file notnot found found System exit 0 System exit 0 catch IOExceptioncatch IOException ie ie System out println IOSystem out println IO error error System exit 0 System exit 0 elseelse 如果文件已经保存过如果文件已经保存过 StringString s s tf getText tf getText 得到所输入的文本内容得到所输入的文本内容 try try 异常处理异常处理 1 filename filename FileFile f f newnew File filename File filename 新建文件新建文件 BufferedWriterBufferedWriter bwbw newnew BufferedWriter BufferedWriter newnew FileWriterFileWriter f f 输入到文件中输入到文件中 bw write s 0 s length bw write s 0 s length bw close bw close catch FileNotFoundExceptioncatch FileNotFoundException fe fe System out println fileSystem out println file notnot found found System exit 0 System exit 0 catch IOExceptioncatch IOException ie ie System out println System out println IOIO error error System exit 0 System exit 0 MenuItemMenuItem mi4 mi4 newnew MenuItem MenuItem 退出退出 mi4 addActionListener newmi4 addActionListener new ActionListener ActionListener 1 publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e System exit 0 System exit 0 MenuItemMenuItem mi5 mi5 newnew MenuItem MenuItem 剪切剪切 mi5 addActionListener newmi5 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e tempStringtempString tf getSelectedText tf getSelectedText 得到要复制的内容 暂存在得到要复制的内容 暂存在 tempStringtempString 中中 StringBufferStringBuffer tmptmp newnew StringBufferStringBuffer tf getText tf getText 临时存储文本临时存储文本 intint startstart tf getSelectionStart tf getSelectionStart 得到要删除的字符串的起始位置得到要删除的字符串的起始位置 intint lenlen tf getSelectedText length tf getSelectedText length 得到要删除的字符串的长度得到要删除的字符串的长度 tmp delete start tmp delete start start len start len 删除所选的字符串删除所选的字符串 tf setText tmp toString tf setText tmp toString 用新文本设置原文本用新文本设置原文本 MenuItemMenuItem mi6 mi6 newnew MenuItem MenuItem 复制复制 1 mi6 addActionListener newmi6 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e tempStringtempString tf getSelectedText tf getSelectedText 得到要复制的内容 暂存在得到要复制的内容 暂存在 tempStringtempString 中中 MenuItemMenuItem mi7 mi7 newnew MenuItem MenuItem 粘贴粘贴 mi7 addActionListener newmi7 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e StringBufferStringBuffer tmptmp newnew StringBufferStringBuffer tf getText tf getText 临时存储文本临时存储文本 intint startstart tf getSelectionStart tf getSelectionStart 得到要粘贴的位置得到要粘贴的位置 tmp insert start tmp insert start tempString tempString tf setText tmp toString tf setText tmp toString 用新文本设置原文本用新文本设置原文本 MenuItemMenuItem mi8 mi8 newnew MenuItem MenuItem 字体字体 mi8 addActionListener newmi8 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e finalfinal DialogDialog d d newnew DialogDialog f f Font Font 新建对话框新建对话框 d setLocation 250 250 d setLocation 250 250 起始位置起始位置 1 d setLayout newd setLayout new BorderLayout BorderLayout 表格布局表格布局 上部分面板上部分面板 LabelLabel l fontl font newnew LabelLabel font font font font 标签标签 PanelPanel p 1 newp 1 new Panel Panel p 1 add l font p 1 add l font p 1 setVisible true p 1 setVisible true 中部面板中部面板 ListList font listfont list newnew ListList 6 6 falsefalse 字体列表字体列表 添加字体项目添加字体项目 font list add Plain font list add Plain 普通字体普通字体 font list add Bold font list add Bold 粗体粗体 font list add Italic font list add Italic 斜体斜体 font list addItemListener new font list addItemListener new PanelPanel p 2p 2 newnew Panel Panel p 2 add font list p 2 add font list p 2 setVisible true p 2 setVisible true 下面部分面板下面部分面板 ButtonButton okok newnew ButtonButton ok ok ok addActionListener newok addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e d dispose d dispose 1 ok setSize ok setSize newnew DimensionDimension 20 20 5 5 PanelPanel p 3p 3 newnew Panel Panel 下部分面板下部分面板 p 3 setVisible true p 3 setVisible true 添加三个面板添加三个面板 d add p 1d add p 1 BorderLayout NORTH BorderLayout NORTH d add p 2d add p 2 BorderLayout CENTER BorderLayout CENTER d add p 3d add p 3 BorderLayout SOUTH BorderLayout SOUTH d pack d pack d addWindowListener d addWindowListener newnew WindowAdapter WindowAdapter 关闭对话框窗口关闭对话框窗口 publicpublic voidvoid windowClosing WindowEventwindowClosing WindowEvent ee ee d dispose d dispose d setVisible true d setVisible true MenuItemMenuItem mi9 mi9 newnew MenuItem MenuItem 小写转换大写小写转换大写 mi9 addActionListener newmi9 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e StringString s s tf getText tf getText 得到所输入的文本内容得到所输入的文本内容 1 StringBufferStringBuffer temptemp newnew StringBuffer StringBuffer for intfor int i i 0 0 i s length i 97if int s charAt i 97 temp append char int s charAt i 32 elseelse temp append s charAt i temp append s charAt i s s newnew String temp String temp tf setText s tf setText s MenuItemMenuItem mi10 mi10 newnew MenuItem MenuItem 大写转换小写大写转换小写 mi10 addActionListener newmi10 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e StringString s s tf getText tf getText 得到所输入的文本内容得到所输入的文本内容 StringBufferStringBuffer temptemp newnew StringBuffer StringBuffer for intfor int i i 0 0 i s length i 65if int s charAt i 65 temp append char int s charAt i 32 1 elseelse temp append s charAt i temp append s charAt i s s newnew String temp String temp tf setText s tf setText s MenuItemMenuItem mi11 mi11 newnew MenuItem MenuItem 帮助帮助 mi11 addActionListener newmi11 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e finalfinal DialogDialog d d newnew DialogDialog f AboutNotpad f AboutNotpad 新建对话框新建对话框 TextAreaTextArea t t newnew TextArea nTextArea n 欢迎使用记事本欢迎使用记事本 n n n n Copyright dongxiuyun Copyright dongxiuyun n n n n free free software software n n n n 版本版本 0 1 0 1 添加标签添加标签 t setSize newt setSize new DimensionDimension 5 5 5 5 t setEditable false t setEditable false d setResizable false d setResizable false 不可改变大小不可改变大小 d add t d add t d pack d pack d addWindowListener newd addWindowListener new WindowAdapter WindowAdapter 关闭对话框窗口关闭对话框窗口 publicpublic voidvoid windowClosing WindowEventwindowClosing WindowEvent ee ee 1 d dispose d dispose d setLocation 100 250 d setLocation 100 250 d setVisible true d setVisible true MenuItemMenuItem mi12 mi12 newnew MenuItem MenuItem 另存为另存为 mi12 addActionListener newmi12 addActionListener new ActionListener ActionListener publicpublic voidvoid actionPerformed ActionEventactionPerformed ActionEvent e e FileDialogFileDialog d newd new FileDialog f FileDialog f save save file file FileDialog SAVEFileDialog SAVE 保存文件对话框保存文件对话框 d addWindowListener d addWindowListener newnew WindowAdapter WindowAdapter 关闭文件对话框窗口关闭文件对话框窗口 publicpublic voidvoid windowClosing WindowEventwindowClosing WindowEvent ee ee System exit 0 System exit 0 d setVisible true d setVisible true StringString s s tf getText tf getText 得到所输入的文本内容得到所输入的文本内容 1 try try 异常处理异常处理 FileFile f f newnew File File d getDirectory d getFile d getDirectory d getFile 新建文件新建文件 BufferedWriterBufferedWriter bwbw newnew BufferedWriter BufferedWriter newnew FileWriterFileWriter f f 输入到文件中输入到文件中 bw write sbw write s 0 0 s length s length bw close bw close catch FileNotFoundExceptioncatch FileNotFoundException fe fe System out println fileSystem out println file notnot found found System exit 0 System exit 0 catch catch IOExceptionIOException ie ie System out println System out println IOIO error error
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 气象指数保险合同
- 食品辐照工艺工程师考试试卷及答案
- 生物质能发电锅炉工程师考试试卷及答案
- 品牌共有运营协议
- 刷好评的协议书的效力
- 注册公司用假租赁协议书
- 盐城装配式造价咨询协议书
- 老祠堂翻新协议书
- 接收培训机构协议书
- 课程资源引进合作协议书
- 2024~2025学年江苏省泰州市兴化市统编版六年级下册期末毕业考试语文试卷
- 门窗厂安全生产管理制度
- 2025年中国品牌在东南亚市场的崛起报告-增长机遇及对区域竞争者的影响-欧睿国际
- 河道治理工程质量管理制度
- 中学实验技能赛方案
- T/CNSS 018-2023预包装食品血糖生成指数标示规范
- 2025内蒙古赤峰林西县招聘社区工作者74人备考考试试题及答案解析
- 城市污水管网沿线绿化与恢复方案
- 新疆保密管理办法
- 肝性脑病合并糖尿病护理
- 方太电烤箱KQD50F-C2说明书
评论
0/150
提交评论