吉林大学珠海学院java课程设计报告.docx

上传人:b****6 文档编号:8612353 上传时间:2023-02-01 格式:DOCX 页数:28 大小:132.16KB
下载 相关 举报
吉林大学珠海学院java课程设计报告.docx_第1页
第1页 / 共28页
吉林大学珠海学院java课程设计报告.docx_第2页
第2页 / 共28页
吉林大学珠海学院java课程设计报告.docx_第3页
第3页 / 共28页
吉林大学珠海学院java课程设计报告.docx_第4页
第4页 / 共28页
吉林大学珠海学院java课程设计报告.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

吉林大学珠海学院java课程设计报告.docx

《吉林大学珠海学院java课程设计报告.docx》由会员分享,可在线阅读,更多相关《吉林大学珠海学院java课程设计报告.docx(28页珍藏版)》请在冰豆网上搜索。

吉林大学珠海学院java课程设计报告.docx

吉林大学珠海学院java课程设计报告

 

课程设计报告

学院、系:

吉林大学珠海学院计算机科学与技术系

专业名称:

计算机科学与技术

课程设计科目

java程序课程设计

学生姓名:

 

指导教师:

朱云

完成时间:

2013.04.20

题目:

功能较完善的文件管理器

一、设计任务与目标

我们选择的题目是:

实现一个能够对文件和文件夹进行各种基本操作的文件管理器窗口程序。

功能要求:

1)新建、删除、修改、复制、黏贴文件功能

2)新建、删除、修改目录

3)具有对某个文件进行压缩打包的功能

4)要求实现多文档界面

5)要求界面美观、功能布局合理。

由于是两个人合作完成所以一开始我们就分工合作,我完成第二和第三个功能,何向强同学完成第一和第四个功能。

由于软件难度还是很大,所以我们研究了很久,大概理清思路!

我曾经阅读过,关于java压缩的书所以通过一点点尝试将写出来,而何向强同学对界面方面比较熟悉,所以他就主要负责界面方面的!

二、方案设计与论证

根据题目的要求,我们想通过JTree来实现遍历文件夹并建成目录树,JList来实现多行显示,界面方面我们准备做成双栏式的,左边目录数,右边文件列表。

由于我们之前没实践过这方面的项目,因此遇到很多困难。

后来,通过阅读javax.swing.JFileChooser类的功能原码来逐步完善,新建、删除、复制等功能我们会通过java.io.File来了解文件的底层操作来完成。

还有增加了一个时钟功能,通过zip进行简单的压缩!

3、程序框图或流程图,程序清单与调用关

四、全部源程序清单

///////////////scaner类/////////////////////

importjavax.swing.*;

importjavax.swing.event.*;

importjavax.swing.tree.*;

importjava.awt.*;

importjava.awt.event.*;

importjava.io.*;

importjava.util.*;

publicclassscanerextendsJFrame

implementsActionListener,TreeExpansionListener,TreeSelectionListener

{JTreejtree=newJTree(createTreeModel());

JPanelJPsub=newJPanel(newGridLayout(0,1));

JPanelroad=newJPanel(newBorderLayout());

JFramef,ff;

JSplitPaneJSP;//可滚动

JButtonsure,ok;

JLabelstatus=newJLabel("");

JLabelshijian,size;

JTextFieldrenamest,zipname;

GregorianCalendartime=newGregorianCalendar();

inthour=time.get(Calendar.HOUR_OF_DAY);

intmin=time.get(Calendar.MINUTE);

intsecond=time.get(Calendar.SECOND);

Vectorv;

JToolBarstatusBar;

JPopupMenupopupMenu;

JMenuItempopupMenu_Copy,popupMenu_Delete,newfiles,p_zip;

JMenuItemcopy,del;

JMenum1,m2,m3;

JMenuItemnewItem,exitItem,zuozhe,help;

JButtonbtt;

JListF_list;

PopupMenumenu;

MenuItemb_open,b_copy,b_jiantie,b_del,newfile,b_rename,b_Zip,newfload;

Object[]dizhi;

FileDialogfd;

longsizes;

Stringnewname;//构造函数

publicscaner()

{super("文件管理器");

//设置窗口大小

Containercontainer=getContentPane();///时钟布局

inti=400;

intj=100;

setBounds(i,j,840,580);

addWindowListener(

newWindowAdapter()

{publicvoidwindowClosing(WindowEventwindowevent)

{System.exit(0);}}};

////////////////////////////////////////////////////////////

m1=newJMenu("文件");

m2=newJMenu("编辑");

m3=newJMenu("帮助");

JMenuBarmenuBar=newJMenuBar();

menuBar.add(m1);

menuBar.add(m2);

menuBar.add(m3);

newItem=newJMenuItem("新建文件");

exitItem=newJMenuItem("退出");

//此时定义完了四个菜单的选项,定义完成之后,增加快捷键

newItem.setMnemonic('N');

exitItem.setMnemonic('E');

newItem.setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK));

exitItem.setAccelerator(KeyStroke.getKeyStroke('E',java.awt.Event.ALT_MASK));

newItem.addActionListener(this);///注册监听器

exitItem.addActionListener(this);

m1.add(newItem);

m1.add(exitItem);

/////////////////////////////

copy=newJMenuItem("复制");

del=newJMenuItem("删除");

//此时定义完了两个菜单的选项,定义完成之后,增加快捷键

copy.setMnemonic('C');

copy.setAccelerator(KeyStroke.getKeyStroke('C',java.awt.Event.ALT_MASK));

m2.add(copy);

m2.add(del);

copy.addActionListener(this);

del.addActionListener(this);

/////////////////////////

zuozhe=newJMenuItem("关于");

help=newJMenuItem("帮助");

m3.add(help);

m3.add(zuozhe);

zuozhe.addActionListener(this);

help.addActionListener(this);

////////////////////////////////

setJMenuBar(menuBar);//菜单是需要通过此方法增加的

setVisible(true);

//frame.setSize(700,500);

setLocation(300,200);

////////////////////////////////////////////////////

//-------------------创建右键弹出菜单

popupMenu=newJPopupMenu();

newfiles=newJMenuItem("新建文件夹");

popupMenu_Copy=newJMenuItem("复制(C)",'C');

popupMenu_Delete=newJMenuItem("删除(D)",'D');

p_zip=newJMenuItem("添加到压缩文件");

//---------------向右键菜单添加菜单项和分隔符

popupMenu.addSeparator();

popupMenu.add(newfiles);

popupMenu.add(popupMenu_Copy);

popupMenu.add(p_zip);

popupMenu.add(popupMenu_Delete);

popupMenu.addSeparator();

//--------------------右键菜单注册事件

popupMenu_Copy.setActionCommand("复制(C)");

popupMenu_Copy.addActionListener(this);

popupMenu_Delete.setActionCommand("删除(D)");

popupMenu_Delete.addActionListener(this);

newfiles.setActionCommand("新建文件夹");

newfiles.addActionListener(this);

p_zip.addActionListener(this);

jtree.add(popupMenu);

/////////////////////////////////////////////////////////////

menu=newPopupMenu();

newfload=newMenuItem("新建文件夹");

newfile=newMenuItem("新建文件");

b_open=newMenuItem("打开");

b_copy=newMenuItem("复制");

b_Zip=newMenuItem("添加到压缩文件");

b_del=newMenuItem("删除");

b_rename=newMenuItem("重命名");

menu.addSeparator();

menu.add(b_open);

menu.add(newfload);

menu.add(newfile);

menu.add(b_copy);

menu.add(b_Zip);

menu.add(b_rename);

menu.add(b_del);

menu.addSeparator();

b_open.addActionListener(this);

newfload.addActionListener(this);

b_copy.addActionListener(this);

b_del.addActionListener(this);

b_Zip.addActionListener(this);

b_rename.addActionListener(this);

newfile.addActionListener(this);

JPsub.add(menu);

//////////////////////////////////////////////////////////////

//水平分割窗口,左scrollPane内放tree,右放JPsub用于显示文件

JSP=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,newJScrollPane(jtree),newJScrollPane(JPsub));

JSP.setDividerLocation(200);////////设置分隔条的位置。

JSP.setLastDividerLocation(200);///////将分隔条所处的最后位置设置为newLastLocation。

getContentPane().add(JSP);//背景色为白

JPsub.setBackground(Color.white);

statusBar=newJToolBar();

shijian=newJLabel("当前时间:

"+hour+":

"+min+":

"+second);

statusBar.addSeparator();

statusBar.add(shijian);

statusBar.setVisible(true);

container.add(statusBar,BorderLayout.SOUTH);

statusBar.setVisible(true);

//////////////////////////////////////////////

//给树添加展开监听器

jtree.addTreeExpansionListener(this);

jtree.addTreeSelectionListener(this);//设置树的外形,改变文件夹的图案

try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

SwingUtilities.updateComponentTreeUI(this);

}

catch(Exceptionex){}

jtree.setShowsRootHandles(true);

getContentPane().add(road,BorderLayout.NORTH);

road.add(status,BorderLayout.WEST);///西边....左边

Clockclock=newClock();////线程

clock.start();

//////////////////////////////////////////////////

f=newJFrame("重命名");

f.setSize(230,80);//设置组件的大小

f.setBackground(Color.WHITE);//将背景设置成白色

f.setLocation(300,200);//设置组件的显示位置

renamest=newJTextField();

sure=newJButton("确定");

f.add(renamest,BorderLayout.CENTER);

f.add(sure,BorderLayout.SOUTH);

sure.addActionListener(this);

//////////////////////////////////////////////////

ff=newJFrame("压缩文件名");

ff.setSize(230,80);//设置组件的大小

ff.setBackground(Color.WHITE);//将背景设置成白色

ff.setLocation(300,200);//设置组件的显示位置

zipname=newJTextField();

ok=newJButton("确定");

ff.add(zipname,BorderLayout.CENTER);

ff.add(ok,BorderLayout.SOUTH);

ok.addActionListener(this);}

////////////实现复制,黏贴功能////////////////////////////

classMainFrameextendsJFrame

{privatestaticfinallongserialVersionUID=1L;

publicMainFrame()

{super("COPY");

setDefaultCloseOperation(HIDE_ON_CLOSE);

setSize(500,260);

setLocation(300,200);

MainPanelpan=newMainPanel();

setContentPane(pan);

setLayout(null);}}

classMainPanelextendsJPanel

{privatestaticfinallongserialVersionUID=1L;

JTextFieldtxt;

JTextAreatxtInFile;

JTextAreatxtOutFile;

JFileChooseropen;

StringstrFilePath;

StringstrFilePathCopyTo;

publicMainPanel()

{JLabellblIn=newJLabel("源文件:

");

lblIn.setBounds(30,65,50,20);

if(F_list.isSelectionEmpty())

txtInFile=newJTextArea(zhantie());

else

txtInFile=newJTextArea(zhantie()+F_list.getSelectedValue());

JScrollPanescrint=newJScrollPane(txtInFile);

scrint.setBounds(80,65,265,40);

JButtonbtnSelect=newJButton("选择文件或目录");

btnSelect.setBounds(350,65,120,20);

open=newJFileChooser();/////////////////////

txtInFile=newJTextArea(zhantie()+F_list.getSelectedValue());

open.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

open.setCurrentDirectory(newFile(zhantie()));

btnSelect.addActionListener(newActionListener()

{publicvoidactionPerformed(ActionEvente)

{open.showOpenDialog(null);

strFilePath=open.getSelectedFile().getPath();///源文件路径

((JButton)e.getSource()).setLabel("已选");

txtInFile.setText(strFilePath);

System.out.println(txtInFile.getText());

System.out.println("打开文件");}}

JLabellblOut=newJLabel("复制到:

");

lblOut.setBounds(30,125,50,20);

txtOutFile=newJTextArea();

txtOutFile.setBounds(80,60,100,20);

JScrollPanescrout=newJScrollPane(txtOutFile);

scrout.setBounds(80,125,265,40);

JButtonbtnSelectCopyTo=newJButton("选择目标路径");

btnSelectCopyTo.setBounds(350,125,120,20);

btnSelectCopyTo.addActionListener(newActionListener()

{publicvoidactionPerformed(ActionEvente)

{if(F_list.isSelectionEmpty())

open.setSelectedFile(newFile(zhantie()));

else

open.setSelectedFile(newFile(zhantie()+F_list.getSelectedValue()));

open.showSaveDialog(null);

strFilePathCopyTo=open.getSelectedFile().getPath();

((JButton)e.getSource()).setLabel("已选");

txtOutFile.setText(strFilePathCopyTo);

System.out.println(txtOutFile.getText());

System.out.println("打开文件");

}}};

JButtonbtnCopy=newJButton("开始复制");

btnCopy.setBounds(130,180,90,20);

btnCopy.addActionListener(newActionListener()

{publicvoidactionPerformed(ActionEvente)

{strFilePath=txtInFile.getText();

strFilePathCopyTo=txtOutFile.getText();

System.out.println(strFilePath);

System.out.println(strFilePathCopyTo);

IOTest.copyFile(strFilePath,strFilePathCopyTo);}}};

add(lblIn);

add(scrint);

add(btnSelect);

add(lblOut);

add(scrout);

add(btnSelectCopyTo);

add(btnCopy);}}

////////////////////////////////////////////////////////

//树展开

publicvoidtreeExpanded

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

当前位置:首页 > 高等教育 > 农学

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

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