java课程设计报告.doc

上传人:w****2 文档编号:6517146 上传时间:2020-02-27 格式:DOC 页数:14 大小:92KB
返回 下载 相关 举报
java课程设计报告.doc_第1页
第1页 / 共14页
java课程设计报告.doc_第2页
第2页 / 共14页
java课程设计报告.doc_第3页
第3页 / 共14页
点击查看更多>>
资源描述
Java课程设计报告 题 目: 文本编辑器 班 级: 学 号: 姓 名: 成 绩: 日期: 年 月 日目 录一、综合设计的目的与要求 3二、综合设计正文31.系统分析31.1系统开发背景、开发范围、建设目标与必要性开发31.2需求分析32.系统设计32.1功能设计32.2系统运行环境与开发工具43 .系统实施43.1源程序43.2. 系统测试及部分截图12三、综合设计总结或结论13四、参考文献13文本编辑器一、综合设计的目的与要求要求在学生能够较熟练使用java程序设计语言进行软件代码的编写,同时还要具备较好的项目分析的能力,加深对相关课程基本内容的理解。同时,在程序设计方法以及上机操作等基本技能和科学作风方面受到比较系统的练习。二、综合设计正文1 系统分析1.1系统开发背景、开发范围、建设目标与必要性随着计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。当然对文本编辑操作仍然占据着重要地位,记事本是简单便捷的文本编辑器,可实现对文本编辑操作的基本功能。1.2需求分析程序设计主要分为两大部分:简单GUI设计和程序功能设计。通过GUI设计实现图形用户界面,提供图形菜单,方便用户操作。使用Java语言编写一个能够对输入文字进行操作,具有合理的界面,能够在界面中实现右键快捷方式,对文档内容进行编辑操作,并且能够顺利退出的程序。通过设计和实现一个具有基本功能的文本编辑器,提高我们对Java语言设计的掌握能力,理论联系实际,进一步提高软件开发技术,从而培养我们分析、解决问题的能力。2 系统设计2.1功能设计根据系统自带的文档编辑器的特征设计,包括如下的功能模块:一、 整体结构框架包括:菜单栏和文档编辑区二、 每个框架分别包含不同的子框架,各个模块的具体框架:1.菜单栏:文件、编辑、工具、帮助2.菜单栏中各个子菜单功能文件:新建、打开、保存、另存为、退出编辑:剪切、复制、粘贴 工具: 查找、替换 3.子菜单功能的实现主要的几个功能介绍1) 打开与另存为:两个窗体调用系统函数直接利用,注意格式的选择2) 查找:查找内容、查找、查找下一个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 JFrame implements ActionListenerString file_name;String file_dir;String tempString;/上次保存后的文件名和地址String fileName = ; JPanel x=new JPanel(); JTextArea wen=new JTextArea(20,50); JMenuItem ziti=new JMenuItem(字体); JMenuItem a=new JMenuItem(普通); /定义菜单项 JMenuItem xin=new JMenuItem(新建); JMenuItem open=new JMenuItem(打开); JMenuItem save=new JMenuItem(保存 ); JMenuItem lsave=new JMenuItem(另存为); JMenuItem tui=new JMenuItem(退出); JMenuItem cut=new JMenuItem(剪切 ); JMenuItem copy=new JMenuItem(复制); JMenuItem cast=new JMenuItem(粘贴); JMenuItem delete=new JMenuItem(删除 ); JMenuItem b=new JMenuItem(粗体); JMenuItem c=new JMenuItem(斜体);TxtEditor() super (文本编辑器);/对话框 setBounds(250,100,700,450); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) int option= JOptionPane.showConfirmDialog( TxtEditor.this, 确定要退出吗. , 系统和你对话 ,JOptionPane.YES_NO_OPTION); if(option=JOptionPane.YES_OPTION) if(e.getWindow() = TxtEditor.this) System.exit(0); else return; ); /热键设置 xin.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK); open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,ActionEvent.CTRL_MASK); save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK); cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MASK); copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK); cast.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK); /定义面板 / x.add( add(new JScrollPane (wen);/);/滚动条 wen.setFont(new Font(楷体 , Font.PLAIN ,20); / wen.setBackground(Color.blue); / add(x); /菜单栏的创建 JMenuBar cai=new JMenuBar(); this.setJMenuBar(cai); cai.setOpaque(true); JMenu jian=new JMenu(文件); jian.add(xin); jian.add(open); jian.add(save); jian.add(lsave); jian.addSeparator( ); jian.add(tui); cai.add(jian); JMenu bian= new JMenu(编辑 ); bian.add(cut); bian.add(copy); bian.add(cast); bian.add(delete); cai.add(bian); JMenu geshi = new JMenu (格式); JMenu optionsMenu=new JMenu(字体); geshi.add(optionsMenu); optionsMenu.add(a); optionsMenu.add(b); optionsMenu.add(c); cai.add(geshi); /增加监听器 xin.addActionListener(this); open.addActionListener(this); save.addActionListener(this); lsave.addActionListener(this); tui.addActionListener(this); cut.addActionListener(this); copy.addActionListener(this); cast.addActionListener(this); delete.addActionListener(this); ziti.addActionListener(this); a.addActionListener(this); b.addActionListener(this); c.addActionListener(this);/ 文本框锁定 /this.setResizable(false); /重写方法public void actionPerformed(ActionEvent e)String actionCommand=e.getActionCommand();if(e.getSource()instanceof JMenu); if(e.getSource()=xin)newfile(); else if(e.getSource()=open) openfile(); else if(e.getSource()=save) savefile(); else if(e.getSource()=lsave) lsavefile(); else if(e.getSource()=cut) cutfile(); else if(e.getSource()=copy) copyfile(); else if(e.getSource()=cast) castfile(); else if(e.getSource()=delete) deletefile(); else if(e.getSource()=a) afile(); else if(e.getSource()=b) bfile(); else if(e.getSource()=c) cfile(); else if(退出.equals(actionCommand) System.exit(0); / 方法定义 public void newfile() savefile(); wen.setText(null); fileName = ; /打开 public void openfile() String fileName = null; FileDialog df = new FileDialog(this,打开文件,FileDialog.LOAD); df.setVisible(true); /建立新文件 File f = new File( df.getDirectory()+df.getFile() ); /得到文件名 fileName = df.getDirectory()+df.getFile(); /用此文件的长度建立一个字符数组 (特别标注) char ch = new char (int)f.length(); /异常处理 try /读出数据,并存入字符数组ch中 BufferedReader bw = new BufferedReader( new FileReader(f) ); bw.read(ch); bw.close(); catch( FileNotFoundException fe ) System.out.println(file not found); System.exit(0); catch( IOException ie) System.out.println(IO error); System.exit(0); String s =new String (ch); wen.setText(s); /保存 public void savefile() if( fileName.equals() ) FileDialog df = new FileDialog(this,保存文件,FileDialog.SAVE); df.addWindowListener( new WindowAdapter() public void windowClosing(WindowEvent ee) System.exit(0); ); df.setVisible(true); String s = wen.getText(); try File f = new File( df.getDirectory()+df.getFile(); fileName = df.getDirectory()+df.getFile(); BufferedWriter bw = new BufferedWriter( new FileWriter (f); bw.write(s , 0 , s.length(); bw.close(); catch(FileNotFoundException fe_) System.out.println(file not found); System.exit(0); catch( IOException ie_) System.out.println( IO error); System.exit(0); /如果文件已经保存过 else String s = wen.getText(); try File f = new File( fileName ); BufferedWriter bw = new BufferedWriter( new FileWriter (f); bw.write(s , 0 , s.length(); bw.close(); catch(FileNotFoundException fe_) System.out.println(file not found); System.exit(0); catch( IOException ie_) System.out.println( IO error); System.exit(0); /另存为 public void lsavefile() FileDialog df = new FileDialog(this,另存为,FileDialog.SAVE); df.addWindowListener( new WindowAdapter() public void windowClosing(WindowEvent ee) System.exit(0); ); df.setVisible(true); String s = wen.getText(); try File f = new File( df.getDirectory()+df.getFile(); BufferedWriter bw = new BufferedWriter( new FileWriter (f); bw.write(s , 0 , s.length(); bw.close(); catch(FileNotFoundException fe_) System.out.println(file not found); System.exit(0); catch( IOException ie_) System.out.println( IO error); System.exit(0); /剪切 public void cutfile() tempString = wen.getSelectedText(); StringBuffer tmp = new StringBuffer ( wen.getText(); int start = wen.getSelectionStart(); int len = wen.getSelectedText().length(); tmp.delete( start , start+len); wen.setText(tmp.toString(); /复制 public void copyfile() tempString = wen.getSelectedText(); /粘贴 public void castfile() StringBuffer tmp = new StringBuffer ( wen.getText(); /得到要粘贴的位置 int start = wen.getSelectionStart(); tmp.insert(start , tempString); /用新文本设置原文本 wen.setText(tmp.toString(); /删除 public void deletefile() StringBuffer tmp = new StringBuffer ( wen.getText(); int start = wen.getSelectionStart(); int len = wen.getSelectedText().length(); tmp.delete( start , start+len); wen.setText(tmp.toString(); /字体 public void afile() wen.setFont(new Font(楷体, Font.PLAIN ,wen.getFont().getSize() );/普通文字 public void bfile() wen.setFont(new Font(楷体 , Font.BOLD ,wen.getFont().getSize() );/粗体文字 public void cfile() wen.setFont(new Font(楷体 , Font.ITALIC ,wen.getFont().getSize() );/斜体文字 public static void main(String args) TxtEditor w=new TxtEditor();w.pack();w.setVisible(true); 3.2系统测试及部分截图4 系统测试三、综合设计总结或结论虽然这次试验比较简单,但是做起来还是比较吃力,由此可见,我在java学习上还不够透彻和明白。通过这次的实验,我对java编程有了更加深刻的了解,遇到问题的时候也能对问题有一个初步的判断,并及时改正。同时也发现自己在java的学习中还只是停留在入门的阶段,还有很多知识都不明白,有些问题改起来也比较麻烦。所以以后还要更加努力学习。四、参考文献1耿祥义 java课程设计 清华大学出版社2张白一 崔尚森 面向对象程序设计-java(第二版) 西安电子科技大学出版社
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 工作总结


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!