文本编辑器课程设计报告.docx

上传人:b****2 文档编号:18252470 上传时间:2023-04-24 格式:DOCX 页数:19 大小:62.90KB
下载 相关 举报
文本编辑器课程设计报告.docx_第1页
第1页 / 共19页
文本编辑器课程设计报告.docx_第2页
第2页 / 共19页
文本编辑器课程设计报告.docx_第3页
第3页 / 共19页
文本编辑器课程设计报告.docx_第4页
第4页 / 共19页
文本编辑器课程设计报告.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

文本编辑器课程设计报告.docx

《文本编辑器课程设计报告.docx》由会员分享,可在线阅读,更多相关《文本编辑器课程设计报告.docx(19页珍藏版)》请在冰豆网上搜索。

文本编辑器课程设计报告.docx

文本编辑器课程设计报告

 

Java课程设计报告

 

题目:

文本编辑器

班级:

学号:

姓名:

成绩:

日期:

年月日

一、综合设计的目的与要求……………………………………3

二、综合设计正文…………………………………………………3

1.系统分析…………………………………………………………3

1.1系统开发背景、开发范围、建设目标与必要性开发……………………3

1.2需求分析…………………………………………………………3

2.系统设计………………………………………………………………3

2.1功能设计…………………………………………………………3

2.2系统运行环境与开发工具……………………………………………4

3.系统实施……………………………………………………………4

3.1源程序……………………………………………………………4

3.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.0EclipseSDK

3系统实施

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(){

super("文本编辑器");

//对话框

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(

add(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);

delete.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();

}

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);

}

catch(IOExceptionie){

System.out.println("IOerror");

System.exit(0);

}

Strings=newString(ch);

wen.setText(s);

}

//保存

publicvoidsavefile(){

if(fileName.equals("")){

FileDialogdf=newFileDialog(this,"保存文件",FileDialog.SAVE);

df.addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEventee){

System.exit(0);

}

});

df.setVisible(true);

Strings=wen.getText();

try

{

Filef=newFile(df.getDirectory()+df.getFile());

fileName=df.getDirectory()+df.getFile();

BufferedWriterbw=newBufferedWriter(newFileWriter(f));

bw.write(s,0,s.length());

bw.close();

}

catch(FileNotFoundExceptionfe_){

System.out.println("filenotfound");

System.exit(0);

}

catch(IOExceptionie_)

{

System.out.println("IOerror");

System.exit(0);

}

}

//如果文件已经保存过

else

{

Strings=wen.getText();

try

{

Filef=newFile(fileName);

BufferedWriterbw=newBufferedWriter(newFileWriter(f));

bw.write(s,0,s.length());

bw.close();

}

catch(FileNotFoundExceptionfe_){

System.out.println("filenotfound");

System.exit(0);

}

catch(IOExceptionie_)

{

System.out.println("IOerror");

System.exit(0);

}

}

}

//另存为

publicvoidlsavefile(){

FileDialogdf=newFileDialog(this,"另存为",FileDialog.SAVE);

df.addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEventee){

System.exit(0);

}

});

df.setVisible(true);

Strings=wen.getText();

try

{

Filef=newFile(df.getDirectory()+df.getFile());

BufferedWriterbw=newBufferedWriter(newFileWriter(f));

bw.write(s,0,s.length());

bw.close();

}

catch(FileNotFoundExceptionfe_){

System.out.println("filenotfound");

System.exit(0);

}

catch(IOExceptionie_)

{

System.out.println("IOerror");

System.exit(0);

}

}

//剪切

publicvoidcutfile(){

tempString=wen.getSelectedText();

StringBuffertmp=newStringBuffer(wen.getText());

intstart=wen.getSelectionStart();

intlen=wen.getSelectedText().length();

tmp.delete(start,start+len);

wen.setText(tmp.toString());

}

//复制

publicvoidcopyfile(){

tempString=wen.getSelectedText();

}

//粘贴

publicvoidcastfile(){

StringBuffertmp=newStringBuffer(wen.getText());

//得到要粘贴的位置

intstart=wen.getSelectionStart();

tmp.insert(start,tempString);

//用新文本设置原文本

wen.setText(tmp.toString());

}

//删除

publicvoiddeletefile(){

StringBuffertmp=newStringBuffer(wen.getText());

intstart=wen.getSelectionStart();

intlen=wen.getSelectedText().length();

tmp.delete(start,start+len);

wen.setText(tmp.toString());

}

//字体

publicvoidafile(){

wen.setFont(newFont("楷体",Font.PLAIN,wen.getFont().getSize()));//普通文字

}

publicvoidbfile(){

wen.setFont(newFont("楷体",Font.BOLD,wen.getFont().getSize()));//粗体文字

}

publicvoidcfile(){

wen.setFont(newFont("楷体",Font.ITALIC,wen.getFont().getSize()));//斜体文字

}

publicstaticvoidmain(String[]args){

TxtEditorw=newTxtEditor();

w.pack();

w.setVisible(true);

}

}

3.2系统测试及部分截图

4系统测试

三、综合设计总结或结论

虽然这次试验比较简单,但是做起来还是比较吃力,由此可见,我在java学习上还不够透彻和明白。

通过这次的实验,我对java编程有了更加深刻的了解,遇到问题的时候也能对问题有一个初步的判断,并及时改正。

同时也发现自己在java的学习中还只是停留在入门的阶段,还有很多知识都不明白,有些问题改起来也比较麻烦。

所以以后还要更加努力学习。

四、参考文献

[1]耿祥义java课程设计清华大学出版社

[2]张白一崔尚森面向对象程序设计---java(第二版)西安电子科技大学出版社

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1