您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > java课程设计报告
1Java课程设计报告题目:文本编辑器班级:学号:姓名:成绩:日期:年月日目录一、综合设计的目的与要求……………………………………3二、综合设计正文…………………………………………………31.系统分析…………………………………………………………31.1系统开发背景、开发范围、建设目标与必要性开发……………………31.2需求分析…………………………………………………………32.系统设计………………………………………………………………32.1功能设计…………………………………………………………32.2系统运行环境与开发工具……………………………………………43.系统实施……………………………………………………………43.1源程序……………………………………………………………43.2.系统测试及部分截图………………………………………………12三、综合设计总结或结论……………………………………………13四、参考文献……………………………………………………………133《文本编辑器》一、综合设计的目的与要求要求在学生能够较熟练使用java程序设计语言进行软件代码的编写,同时还要具备较好的项目分析的能力,加深对相关课程基本内容的理解。同时,在程序设计方法以及上机操作等基本技能和科学作风方面受到比较系统的练习。二、综合设计正文1系统分析1.1系统开发背景、开发范围、建设目标与必要性随着计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。当然对文本编辑操作仍然占据着重要地位,记事本是简单便捷的文本编辑器,可实现对文本编辑操作的基本功能。1.2需求分析程序设计主要分为两大部分:简单GUI设计和程序功能设计。通过GUI设计实现图形用户界面,提供图形菜单,方便用户操作。使用Java语言编写一个能够对输入文字进行操作,具有合理的界面,能够在界面中实现右键快捷方式,对文档内容进行编辑操作,并且能够顺利退出的程序。通过设计和实现一个具有基本功能的文本编辑器,提高我们对Java语言设计的掌握能力,理论联系实际,进一步提高软件开发技术,从而培养我们分析、解决问题的能力。2系统设计2.1功能设计根据系统自带的文档编辑器的特征设计,包括如下的功能模块:一、整体结构框架包括:菜单栏和文档编辑区二、每个框架分别包含不同的子框架,各个模块的具体框架:1.菜单栏:文件、编辑、工具、帮助2.菜单栏中各个子菜单功能文件:新建、打开、保存、另存为、退出编辑:剪切、复制、粘贴工具:查找、替换3.子菜单功能的实现主要的几个功能介绍41)打开与另存为:两个窗体调用系统函数直接利用,注意格式的选择2)查找:查找内容、查找、查找下一个4.文本编辑区监视文本内容是否改变、监听光标所在位置2.2系统运行环境与开发工具开发环境与工具:jdk2.0EclipseSDK3系统实施3.1源程序importjavax.swing.*;importjava.awt.*;importjava.io.*;importjava.awt.event.*;publicclassTxtEditorextendsJFrameimplementsActionListener{Stringfile_name;Stringfile_dir;StringtempString;//上次保存后的文件名和地址StringfileName=;JPanelx=newJPanel();JTextAreawen=newJTextArea(20,50);JMenuItemziti=newJMenuItem(字体);JMenuItema=newJMenuItem(普通);//定义菜单项JMenuItemxin=newJMenuItem(新建);JMenuItemopen=newJMenuItem(打开);JMenuItemsave=newJMenuItem(保存);JMenuItemlsave=newJMenuItem(另存为);JMenuItemtui=newJMenuItem(退出);JMenuItemcut=newJMenuItem(剪切);JMenuItemcopy=newJMenuItem(复制);JMenuItemcast=newJMenuItem(粘贴);JMenuItemdelete=newJMenuItem(删除);JMenuItemb=newJMenuItem(粗体);JMenuItemc=newJMenuItem(斜体);TxtEditor(){5super(文本编辑器);//对话框setBounds(250,100,700,450);setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){intoption=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(6add(newJScrollPane(wen));//);//滚动条wen.setFont(newFont(楷体,Font.PLAIN,20));//wen.setBackground(Color.blue);//add(x);//菜单栏的创建JMenuBarcai=newJMenuBar();this.setJMenuBar(cai);cai.setOpaque(true);JMenujian=newJMenu(文件);jian.add(xin);jian.add(open);jian.add(save);jian.add(lsave);jian.addSeparator();jian.add(tui);cai.add(jian);JMenubian=newJMenu(编辑);bian.add(cut);bian.add(copy);bian.add(cast);bian.add(delete);cai.add(bian);JMenugeshi=newJMenu(格式);JMenuoptionsMenu=newJMenu(字体);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);7delete.addActionListener(this);ziti.addActionListener(this);a.addActionListener(this);b.addActionListener(this);c.addActionListener(this);//文本框锁定//this.setResizable(false);}//重写方法publicvoidactionPerformed(ActionEvente){StringactionCommand=e.getActionCommand();if(e.getSource()instanceofJMenu);{if(e.getSource()==xin){newfile();}elseif(e.getSource()==open){openfile();}elseif(e.getSource()==save){savefile();}elseif(e.getSource()==lsave){lsavefile();}elseif(e.getSource()==cut){cutfile();}elseif(e.getSource()==copy){copyfile();}elseif(e.getSource()==cast){castfile();}elseif(e.getSource()==delete){deletefile();}elseif(e.getSource()==a){afile();8}elseif(e.getSource()==b){bfile();}elseif(e.getSource()==c){cfile();}elseif(退出.equals(actionCommand))System.exit(0);}}//方法定义publicvoidnewfile(){savefile();wen.setText(null);fileName=;}//打开publicvoidopenfile(){StringfileName=null;FileDialogdf=newFileDialog(this,打开文件,FileDialog.LOAD);df.setVisible(true);//建立新文件Filef=newFile(df.getDirectory()+df.getFile());//得到文件名fileName=df.getDirectory()+df.getFile();//用此文件的长度建立一个字符数组(特别标注)charch[]=newchar[(int)f.length()];//异常处理try{//读出数据,并存入字符数组ch中BufferedReaderbw=newBufferedReader(newFileReader(f));bw.read(ch);bw.close();}catch(FileNotFoundExceptionfe){System.out.println(filenotfound);System.exit(0);}9catch(IOExceptionie){System.out.println(IOerror);System.exit(0);}Strings=newString(ch);wen.setText(s);}//保存publicvoidsavefile(){if(fileName.equals
本文标题:java课程设计报告
链接地址:https://www.777doc.com/doc-2227007 .html