功能较完善的文件管理器java课程设计报告毕业设计(论文)
更新时间:2023-12-24 11:47:01 阅读量: 教育文库 文档下载
功能较完善的文件管理器
一、设计任务与目标
实现一个能够对文件和文件夹进行各种基本操作的文件管理器窗口程序。 功能要求:
1)新建、删除、修改、复制、黏贴文件功能 2)新建、删除、修改目录
3)具有对某个文件进行压缩打包的功能 4)要求实现多文档界面
5)要求界面美观、功能布局合理。
二、方案设计与论证
根据题目的要求,我们想通过JTree来实现遍历文件夹并建成目录树,JList来实现多行显示,界面方面我们准备做成双栏式的,左边目录数,右边文件列表,通过阅读javax.swing.JFileChooser类的功能原码来逐步完善,新建、删除、复制等功能我们会通过java.io.File来了解文件的底层操作来完成。
三、程序框图或流程图,程序清单与调用关系
main主函数构造函数scaner()MainFrametreeExpandtreeCollapvalueChang类ed树侦听器sed树折叠ed树值变化 swap交换actionPerfsortElemensortElemenaddlist右边ormed事件监FileNode类ts排序ts排序文件列表听Clock类构造函数MainFrame()mousePressmouseClicked鼠标监听ed鼠标监听MainPanel类IOTest类构造函数构造函数构造函数ZIPUtil类newFolder(delFolder(delFile()))构造函数构造函数createTreeZhantie()Model() addActionListener监听器构造函数delAllFile()
四、全部源程序清单
/////////////// scaner类///////////////////// import javax.swing.*;
import javax.swing.event.*; import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*; import java.io.*; import java.util.*;
public class scaner extends JFrame
implements ActionListener,TreeExpansionListener,TreeSelectionListener {
/** * */
private static final long serialVersionUID = -6653169472316161951L; //定义常量
JTree jtree = new JTree(createTreeModel()); JPanel JPsub=new JPanel(new GridLayout(0,1)); JPanel road=new JPanel(new BorderLayout()); JFrame f,ff;
JSplitPane JSP; //可滚动 JButton sure,ok;
JLabel status=new JLabel(\); JLabel shijian,size;
JTextField renamest,zipname;
GregorianCalendar time = new GregorianCalendar(); int hour = time.get(Calendar.HOUR_OF_DAY); int min = time.get(Calendar.MINUTE); int second = time.get(Calendar.SECOND); Vector
JMenuItem popupMenu_Copy, popupMenu_Delete,newfiles,p_zip; JMenuItem copy,del; JMenu m1, m2, m3;
JMenuItem newItem, exitItem, zuozhe, help; JButton btt; JList F_list; PopupMenu menu;
MenuItem b_open, b_copy, b_jiantie, b_del,newfile,b_rename,b_Zip,newfload; Object[] dizhi; FileDialog fd; long sizes; String newname;
//构造函数
public scaner() {
super(\文件管理器\); //设置窗口大小
Container container = getContentPane();///时钟布局 int i = 400; int j = 100;
setBounds(i,j,840,580);
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent windowevent) {
System.exit(0); } } );
//////////////////////////////////////////////////////////// m1 = new JMenu(\文件\) ; m2 = new JMenu(\编辑\) ; m3 = new JMenu(\帮助\) ;
JMenuBar menuBar = new JMenuBar() ; menuBar.add(m1) ; menuBar.add(m2) ; menuBar.add(m3) ;
newItem = new JMenuItem(\新建文件\) ; exitItem = new JMenuItem(\退出\) ;
// 此时定义完了四个菜单的选项,定义完成之后,增加快捷键 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 = new JMenuItem(\复制\) ; del = new JMenuItem(\删除\) ;
// 此时定义完了两个菜单的选项,定义完成之后,增加快捷键
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 = new JMenuItem(\关于\) ; help = new JMenuItem(\帮助\); m3.add(help); m3.add(zuozhe);
zuozhe.addActionListener(this); help.addActionListener(this); ////////////////////////////////
setJMenuBar(menuBar) ; // 菜单是需要通过此方法增加的 setVisible(true) ;
//frame.setSize(700,500) ; setLocation(300,200);
//////////////////////////////////////////////////// // -------------------创建右键弹出菜单 popupMenu = new JPopupMenu();
newfiles=new JMenuItem(\新建文件夹\);
popupMenu_Copy = new JMenuItem(\复制(C)\, 'C');
popupMenu_Delete = new JMenuItem(\删除(D)\, 'D'); p_zip =new JMenuItem(\添加到压缩文件\);
// ---------------向右键菜单添加菜单项和分隔符 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 = new PopupMenu();
newfload=new MenuItem(\新建文件夹\); newfile=new MenuItem(\新建文件\); b_open=new MenuItem(\打开\); b_copy=new MenuItem(\复制\);
b_Zip=new MenuItem(\添加到压缩文件\); b_del=new MenuItem(\删除\);
b_rename=new MenuItem(\重命名\); 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=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(jtree),new JScrollPane(JPsub));
JSP.setDividerLocation (200);////////设置分隔条的位置。
JSP.setLastDividerLocation(200); /////// 将分隔条所处的最后位置设置为 newLastLocation。
getContentPane().add(JSP);
//背景色为白
JPsub.setBackground(Color.white); //////////////////////////////////////
/////////////////////////////////////////////时间///////////////////////
statusBar = new JToolBar();
shijian = new JLabel(\当前时间:\ + 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(\AndFeel\);
SwingUtilities.updateComponentTreeUI(this); }
catch (Exception ex) {}
jtree.setShowsRootHandles(true);
getContentPane().add(road,BorderLayout.NORTH); road.add(status,BorderLayout.WEST); ///西边....左边 Clock clock=new Clock();////线程 clock.start();
////////////////////////////////////////////////// f = new JFrame(\重命名\) ;
f.setSize(230,80) ; // 设置组件的大小
f.setBackground(Color.WHITE) ; // 将背景设置成白色 f.setLocation(300,200) ; // 设置组件的显示位置 renamest=new JTextField(); sure=new JButton(\确定\);
f.add(renamest,BorderLayout.CENTER); f.add(sure,BorderLayout.SOUTH); sure.addActionListener(this);
////////////////////////////////////////////////// ff = new JFrame(\压缩文件名\) ;
ff.setSize(230,80) ; // 设置组件的大小 ff.setBackground(Color.WHITE) ; // 将背景设置成白色 ff.setLocation(300,200) ; // 设置组件的显示位置 zipname=new JTextField(); ok=new JButton(\确定\);
ff.add(zipname,BorderLayout.CENTER); ff.add(ok,BorderLayout.SOUTH); ok.addActionListener(this); }
////////////实现复制,黏贴功能//////////////////////////// class MainFrame extends JFrame { /** * */
private static final long serialVersionUID = 1L;
public MainFrame() {
super(\);
setDefaultCloseOperation(HIDE_ON_CLOSE); setSize(500,260);
setLocation(300,200) ;
MainPanel pan = new MainPanel(); setContentPane(pan); setLayout(null); }
}
class MainPanel extends JPanel {
/** * */
private static final long serialVersionUID = 1L; JTextField txt;
JTextArea txtInFile; JTextArea txtOutFile; JFileChooser open; String strFilePath;
String strFilePathCopyTo; public MainPanel() {
JLabel lblIn = new JLabel(\源文件:\); lblIn.setBounds(30, 65, 50, 20); if(F_list.isSelectionEmpty())
txtInFile = new JTextArea(zhantie()); else
txtInFile = new JTextArea(zhantie()+F_list.getSelectedValue()); JScrollPane scrint = new JScrollPane(txtInFile) ; scrint.setBounds(80,65,265,40);
JButton btnSelect = new JButton(\选择文件或目录\); btnSelect.setBounds(350, 65, 120, 20);
open = new JFileChooser();/////////////////////
txtInFile = new JTextArea(zhantie()+F_list.getSelectedValue()); open.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); open.setCurrentDirectory(new File(zhantie())); btnSelect.addActionListener(new ActionListener() {
@SuppressWarnings(\)
public void actionPerformed(ActionEvent e) {
open.showOpenDialog(null);
strFilePath = open.getSelectedFile().getPath();///源文件路径 ((JButton)e.getSource()).setLabel(\已选\); txtInFile.setText(strFilePath);
System.out.println(txtInFile.getText());
System.out.println(\打开文件\); } } );
JLabel lblOut = new JLabel(\复制到:\); lblOut.setBounds(30, 125, 50, 20); txtOutFile = new JTextArea();
txtOutFile.setBounds(80,60,100,20);
JScrollPane scrout = new JScrollPane(txtOutFile) ; scrout.setBounds(80,125,265,40);
JButton btnSelectCopyTo = new JButton(\选择目标路径\); btnSelectCopyTo.setBounds(350, 125, 120, 20);
btnSelectCopyTo.addActionListener(new ActionListener() {
@SuppressWarnings(\)
public void actionPerformed(ActionEvent e) {
if(F_list.isSelectionEmpty())
open.setSelectedFile(new File(zhantie())); else
open.setSelectedFile(new
File(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(\打开文件\); } } );
JButton btnCopy = new JButton(\开始复制\); btnCopy.setBounds(130, 180, 90, 20);
btnCopy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
正在阅读:
功能较完善的文件管理器java课程设计报告毕业设计(论文)12-24
图像增强技术综述10-03
赞美雪的句子03-17
关于村干部挂职乡镇机关锻炼的实践与思考02-15
热处理工试题带答案09-24
感受信息处处在 - 图文11-09
高考语文专题复习:辨析并修改病句04-14
关于做好县级工会帮扶工作的思考10-17
新疆电大汉语言文学专业专科毕业大作业答案11-18
C语言讲义101-23
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 文件管理器
- 毕业设计
- 完善
- 课程
- 功能
- 报告
- 论文
- 设计
- java
- 科学技术在人类社会发展中的作用
- 2019年人教版小学四年级数学下册全册单元测试题及答案(包括期中期末考试题)
- 迈普3G专业级路由器构建更加灵活的企业网络
- 2012年全国中考数学压轴题分类解析汇编 专题2 函数问题
- 永兴铝材检验标准
- 在XX市融资担保公司和小额贷款公司工作会议上的发言
- 幼儿园教师培训工作总结与幼儿园教师培训心得体会4篇合集
- 四川美术学院“绿色校园”建设实施方案
- 人教版新教材高二数学第七章精品教案全集 rar-人教版 高二数学7.2直线的方程(三课时) - 175
- 2014年安徽教师招聘:2014年安徽建筑大学招聘7名辅导员公告
- 音体美组教研活动
- 600MW超临界机组协调控制系统的应用研究 - 图文
- X局网络管理和使用办法
- 幼儿园教案去海边
- 最新数学湘教版初中九年级下册1.3 不共线三点确定二次函数的表达式导学案
- 小学英语课堂教学的误区和对策
- 中国的红色政权为什么能够存在 读书报告(原创)
- 工期保证措施专项方案及承诺书
- 公益广告对企业品牌建设及传播的作用
- 波尔多酒店茶楼营销计划书 - 图文