用java实现的资源管理器

该博客介绍了使用Java实现资源管理器的功能,包括树形结构显示、菜单操作、文件夹和文件的各种操作。博主分享了实现思路,如用JTree、JMenu、JTable等组件,并提供了部分关键代码,如拖拽操作、文件拷贝、渲染和动态构建树结构。同时,博主提醒在启动时避免一次性遍历所有系统目录以减少资源消耗。
摘要由CSDN通过智能技术生成

功能分析

  • 资源管理器树形结构的显示。
  • 菜单的显示和操作。
  • 文件夹的操作,新建、删除、拷贝、移动等。
  • 文件的操作,新建、删除、拷贝、移动等。
  • 参考Linux和windows下的资源管理器。

实现思路

  • 用JTree实现资源管理器树形结构的显示
  • 用JMenu实现菜单的显示和操作
  • 用JTable显示文件夹中的文件及子文件夹
  • 用File实现对文件及文件夹的操作
  • 用JPopupMenu实现右键菜单的显示和操作
  • 用DefaultTableCellRenderer和DefaultTreeCellRenderer分别对JTree和JTable进行渲染,添加图标
  • 用FileChannel实现文件的拷贝粘贴
  • 用DragSource和DropTarget实现以拖拽形式对文件进行移动

部分代码

  • 以拖拽形式对文件进行移动
    DragSource dragSource = DragSource.getDefaultDragSource();
    //Once the DragSource is obtained, a DragGestureRecognizer should also be obtained to associate the DragSource with a particular Component.
    DragGestureRecognizer dgr = dragSource.createDefaultDragGestureRecognizer(table, DnDConstants.ACTION_MOVE, new DragGestureListener() {

        public void dragGestureRecognized(DragGestureEvent dge) {
            // TODO Auto-generated method stub
            Toolkit tk = Toolkit.getDefaultToolkit();
            Dimension dim = tk.getBestCursorSize(draggedIcon.getIconWidth(),draggedIcon.getIconHeight()); 
            BufferedImage buff = new BufferedImage(dim.width,dim.height,BufferedImage.TYPE_INT_ARGB);
            draggedIcon.paintIcon(table,buff.getGraphics(),0,0);
            //Reports whether or not drag Image support is available on the underlying platform.
            if(DragSource.isDragImageSupported()) {    
                Transferable tr = new StringSelection(pathOfFileToMove); 
                dge.startDrag(DragSource.DefaultMoveDrop,buff,new Point(0,0),tr,new DragSourceListener() {

                    public void dropActionChanged(DragSourceDragEvent arg0) {
                        // TODO Auto-generated method stub

                    }

                    public void dragOver(DragSourceDragEvent arg0) {
                        // TODO Auto-generated method stub</
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值