Java综合性实验报告文档格式.docx

上传人:b****1 文档编号:1509811 上传时间:2023-04-30 格式:DOCX 页数:30 大小:513.31KB
下载 相关 举报
Java综合性实验报告文档格式.docx_第1页
第1页 / 共30页
Java综合性实验报告文档格式.docx_第2页
第2页 / 共30页
Java综合性实验报告文档格式.docx_第3页
第3页 / 共30页
Java综合性实验报告文档格式.docx_第4页
第4页 / 共30页
Java综合性实验报告文档格式.docx_第5页
第5页 / 共30页
Java综合性实验报告文档格式.docx_第6页
第6页 / 共30页
Java综合性实验报告文档格式.docx_第7页
第7页 / 共30页
Java综合性实验报告文档格式.docx_第8页
第8页 / 共30页
Java综合性实验报告文档格式.docx_第9页
第9页 / 共30页
Java综合性实验报告文档格式.docx_第10页
第10页 / 共30页
Java综合性实验报告文档格式.docx_第11页
第11页 / 共30页
Java综合性实验报告文档格式.docx_第12页
第12页 / 共30页
Java综合性实验报告文档格式.docx_第13页
第13页 / 共30页
Java综合性实验报告文档格式.docx_第14页
第14页 / 共30页
Java综合性实验报告文档格式.docx_第15页
第15页 / 共30页
Java综合性实验报告文档格式.docx_第16页
第16页 / 共30页
Java综合性实验报告文档格式.docx_第17页
第17页 / 共30页
Java综合性实验报告文档格式.docx_第18页
第18页 / 共30页
Java综合性实验报告文档格式.docx_第19页
第19页 / 共30页
Java综合性实验报告文档格式.docx_第20页
第20页 / 共30页
亲,该文档总共30页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

Java综合性实验报告文档格式.docx

《Java综合性实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《Java综合性实验报告文档格式.docx(30页珍藏版)》请在冰点文库上搜索。

Java综合性实验报告文档格式.docx

总体设计、具体设计、数据结构设计等。

18

4.程序设计(30):

面向对象程序设计方法与编程工具掌握水平。

27

5.界面设计(15):

界面美观程度、操作方式友好程度等。

6.论文撰写(10):

论文撰写的规范性、合理性等等。

小组总成绩:

91

教师签名

宋鸿陟

日期

1系统分析

1.1问题描述

源程序代码是纯文本文件,本课程设计的目标是编写一个应用程序可以将源程序文件转换为HTML的网页文件。

1.2系统功能分析

功能要求如下:

1.能够处理的源程序包括:

Java源程序(扩展名.java)、C源程序(扩展名.h和.c)。

鼓励能处理其他源程序代码。

2.提供一个基于JavaSwing实现的GUI界面,类似Windows的资源管理器。

在该界面中选择一个或多个源程序文件进行转换。

3.转换时要求按语法分色。

因此需要该对转换进行设置,如:

目标文件名、字体、关键字颜色等。

4.得到的HTML文件,用浏览器查看如下图所示。

另外要求每行有行号。

1.3开发平台及工具介绍

使用Eclipse进行代码编写,后在Netbeants中导入Eclipise项目进行打包

2系统设计

2.1系统总体结构设计

2.1.1配置文件:

该语言的关键字

配色方案,如:

关键字字体的颜色、大小;

标识符的字体颜色、大小

配置文件的格式可以是:

cpp或Java的properties文件

2.1.2导入的包

importjava.awt.*;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.awt.event.FocusEvent;

importjava.awt.event.FocusListener;

importjava.awt.event.MouseAdapter;

importjava.awt.event.MouseEvent;

importjava.io.File;

importjava.io.FileInputStream;

importjava.io.FileOutputStream;

importjava.io.IOException;

importjava.io.InputStream;

importjava.util.ArrayList;

importjava.util.Date;

importjava.util.Properties;

importjavax.swing.border.BevelBorder;

importjavax.swing.event.ListDataListener;

importjavax.swing.event.TreeModelListener;

importjavax.swing.event.TreeSelectionEvent;

importjavax.swing.event.TreeSelectionListener;

importjavax.swing.filechooser.FileSystemView;

importjavax.swing.tree.*;

importjavax.swing.*;

importjavax.swing.tree.DefaultTreeCellRenderer

2.1.3html转换

首先要理解HTML文件和源程序文件都是文本文件,因此使用Java的文本输入流读入,文本输出流输出。

中间因为要分词,所以可能用到:

Scanner、Buffer、正则表达式等。

2.2系统各个类及类之间关系设计

2.2.1构成界面的类

publicclassMyFranme(面板)

classJMenubarAndJToolbarextendsJPanel(面板)

classfontJFrameextendsJFrame(字体设置面板)

classJOpen(打开文件类)

classMyJPopupMenusextendsJPopupMenu(右键菜单)

classFileNode(文件结点类)

classMyTreeModelimplementsTreeModel(树形结点,借FileNode中的函数实现TreeModel接口)

classMyDefaultTreeCellRendererextendsDefaultTreeCellRenderer(定义自己树形的结点渲染器,实现在树形结点加入文件图标)

classMyJTreeextendsJTreeimplementsTreeSelectionListener

classMyListCellRendererextendsJLabelimplementsListCellRenderer(设置列表属性、图标icon、颜色)

classFileListModelimplementsListModel(设置列表模式)

classMyJListextendsJList(右键菜单实现类)

classMyJPanelextendsJPanel(定义程序面板)

classblankset(缩进设置)

2.2.2代码转换类

publicclassMyMain(包含staticvoidinitialize(Stringext)throwsIOException//判断文件是否为可转换文件,

publicMyMain(Filefile)

publicstaticStringFormat(Stringstr)//调整空格,让现实更加美观,默认5个空格

publicstaticStringannotationDeal(Stringstr,Stringcolor)//注释识别和字串与关键字的上色,递归实现

publicstaticbooleancheck(Stringstr)//判断分号操作先还是注释先

publicstaticintchangetimes(intindex,Stringstr)//转意字符个数

publicstaticStringkeyWordAndStringDeal(Stringstr)//关键字和字符变色

publicstaticStringcharColorful(Stringstr)//字符变色

publicstaticStringkeycolorful(Stringfrom,Stringto,Stringsource)//关键字添加颜色等方法)

publicclassconfig(字符转换)

2.2.3文件复制类

publicclassCopyfile(包含方法:

publicstaticbooleanCopyDirectory(FilesourceDirectory,FiledestinationDirection,booleanoverlay)//复制目录中的所有文件

publicstaticbooleanCopyFile(FilesourceFile,FiledestinationFile,booleanoverlay)//复制单个文件)

2.3数据存储的设计(文件等)

基本数据存储说明:

支持代码格式:

包括java,c,c++,等三种源代码文件

输入:

以*.java,*.c,*.h,文件存储的源代码

输出:

文件格式为*.html

 

2.4界面设计

2.4.1实现用JavaSwing构造的GUI界面,进行图形化操作与显示

综合利用各种对象如JMenuBar、JMenu、JMenuItem、JButton、JPanel、JComponent、JComboBox、JLabel、JTextField、BorderLayout、Connection、JTextArea进行界面的规划布局;

2.4.2对界面中必要的元件实例编写事件驱动如JButton、JComboBox等

解决办法:

在该必要的元件调用方法(get+“元件名称”)中直接添加ActionListener(监听器)方法;

即:

实例.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEvente){

//事件触发执行代码

}

3系统实现

3.1流程图:

程序主界面

输出文件

代码转换

配置文件选取

选择文件

3.2菜单栏的设置

Menubar包括设置,退出,关于三个菜单按钮

设置按钮中加入fontitem(字体),blankitem(缩进)两个对象

退出按钮中加入exititem(确定)对象

关于按钮中加入helpitem(制作人)对象

代码如下:

JMenuItemfontitem=newJMenuItem("

字体"

);

JMenuItemblankitem=newJMenuItem("

缩进"

JMenuItemexititem=newJMenuItem("

确定"

JMenuItemhelpitem=newJMenuItem("

制作人"

menubar=newJMenuBar();

menubar.add(toolsmenu=newJMenu("

设置"

));

menubar.add(filemenu=newJMenu("

退出"

menubar.add(helpmenu=newJMenu("

关于"

filemenu.add(exititem);

helpmenu.add(helpitem);

toolsmenu.add(fontitem);

toolsmenu.add(blankitem);

3.3文默认打开方式

系统选中的可转换格式的文件(包括.java.cpp.h.js.c等文件格式)可以通过调用系统中的文本打开方式打开,实现代码如下:

classJOpen{

publicstaticvoidopenFiles(StringopenPath){

inttemp=openPath.lastIndexOf("

."

if(temp!

=-1){

Stringext=openPath.substring(temp);

//获取文件格式

ext=ext.toLowerCase();

if(ext.equals("

.txt"

)||ext.equals("

.java"

.cpp"

||ext.equals("

.h"

.js"

.c"

)){

try{

//打开源文件

Runtime.getRuntime().exec(

"

C:

\\WINDOWS\\system32\\notepad.exe"

+openPath);

}catch(IOExceptione){

e.printStackTrace();

}

}elseif(ext.equals("

.html"

.htm"

Desktopdp=Desktop.getDesktop();

try{//打开目标文件

dp.open(newFile(openPath));

}

}

}

3.4文件右键可以出现选择菜单

myMenubar对象可以出现:

转换代码、打开、粘贴和删除五个选项

MyJPopupMenus(){

myMenubar=newJPopupMenu();

myMenubar.add(transformItem=newJMenuItem("

转换代码"

myMenubar.add(openItem=newJMenuItem("

打开"

myMenubar.add(copyItem=newJMenuItem("

复制"

myMenubar.add(pasteItem=newJMenuItem("

粘贴"

myMenubar.add(delectItem=newJMenuItem("

删除"

myMenubar.setPopupSize(100,220);

this.add(myMenubar);

3.5树状结构的实现

3.5.1文件结点类

classFileNode{

privatestaticcharallSelected='

A'

;

//列表用

privatestaticcharisDirectory='

D'

//树状图用,做目录

privatestaticcharFile='

F'

privatestaticbooleannoHiden=true;

//定义是否显示隐藏

privatestaticFileSystemViewfsv=null;

//定义文件系统显示类

privateFilefile=null;

privateArrayList<

File>

allFiles=newArrayList<

();

//所有文件的数组

folder=newArrayList<

//存放子目录文件的数组

publicFileNode(){

//因为FileSystemView是抽象类,不能实例化的,用getFileSystemView()可以得到FileSystemView的一个实例,进而调用其非静态方法

fsv=FileSystemView.getFileSystemView();

file=fsv.getHomeDirectory();

//getHomeDirectory获得桌面路径对象

prepareChildren();

publicFileNode(Filefile){

this.file=file;

//获取显示的(即未隐藏)文件的列表,在下面定义

//设置是否显示隐藏

publicvoidsetHiden(booleanselected){

noHiden=selected;

//获得图标

publicIcongetIcon(){

returnfsv.getSystemIcon(file);

//返回文件绝对路径

publicStringfileAbsoluteDir(){

Strings=null;

s=file.getAbsolutePath();

returns;

//获取显示的(即未隐藏)文件的列表

privatevoidprepareChildren(){

File[]files=fsv.getFiles(file,noHiden);

for(inti=0;

i<

files.length;

i++){

allFiles.add(files[i]);

if(files[i].isDirectory()){

folder.add(files[i]);

//删除文件

publicvoidremoveFile(intindex){

allFiles.remove(index);

//用于判断结点是树状列表的叶子

publicbooleanisLeaf(charfileType){

if(isDirectory==fileType){

returnfolder.isEmpty();

}elseif(allSelected==fileType){

returnallFiles.isEmpty();

}elseif(File==fileType){

returntrue;

}else{

//获取树状图中的文件对象

publicFileNodegetChild(charfileType,intindex){

returnnewFileNode(folder.get(index));

returnnewFileNode(allFiles.get(index));

returnnull;

//获取子结点的数量

publicintgetChildCount(charfileType){

returnfolder.size();

returnallFiles.size();

return-1;

//返回文件索引项,以确定所选的子结点的位置

publicintgetIndexOfChild(charfileType,Objectchild){

if(childinstanceofFileNode){

if(isDirectory==fileType){

returnfolder.indexOf(((FileNode)child).file);

}elseif(allSelected==fileType){

returnallFiles.indexOf(((FileNode)child).file);

}elseif(File==fileType){

return-1;

}else{

//重载toString()函数,后面设置列表属性需要

@Override

publicStringtoString(){

returnfsv.getSystemDisplayName(file);

3.5.2树形结点,借FileNode中的函数实现TreeModel接口

classMyTreeModelimplementsTreeModel{

FileNodefilenode=null;

staticcharfileType='

//定义结点类型为目录,便于与isDirectory匹配

publicMyTreeModel(FileNodefilenode){

this.filenode=filenode;

publicvoidaddTreeModelListener(TreeModelListenere){

//TODOAuto-generatedmethodstub

publicObjectgetChild(Objectparent,intindex){

return((FileNode)parent).getChild(fileType,index);

publicintgetChildCount(Objectparent){

return((FileNode)parent).getChildCount(fileType);

publicintgetIndexOfChild(Objectparent,Objectchild){

return((FileNode)parent).getIndexOfChild(fileType,child);

publicObjectgetRoot(){

returnfilenode;

publicbooleanisLeaf(Objectfilenode){

return((FileNode)filenode).isLeaf(fileType);

pu

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

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2