




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class FileCutterpublic static void main(String args)EventQueue.invokeLater(new Runnable()public void run()CutterFrame myFrame = new CutterFrame();myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);myFrame.setVisible(true););class CutterFrame extends JFrame/创建框架private int Height;private int Width;public CutterFrame()/获取屏幕信息Toolkit kit=Toolkit.getDefaultToolkit();Dimension screenSize=kit.getScreenSize();Height=screenSize.height; Width=screenSize.width; /设置大小和位置setBounds(Width/3,Height/8,Width/3,(Height*2)/3);setTitle(Super Cutter Frame);/添加面板CutPanel aCutPanel=new CutPanel(Height,Width/3);MergePanel aMergePanel=new MergePanel(Height,Width/3);/添加选项卡JTabbedPane tp=new JTabbedPane(SwingConstants.TOP); add(tp); tp.add(aCutPanel,File Cut); tp.add(aMergePanel,File Merge);class CutPanel extends JPanelprivate String FileName=;private String Target=;private int Size=0; private int FileSize=0; private int Number=0; /进度条 private JProgressBar CutProgressBar=new JProgressBar(); /标签private JLabel Label_Name=new JLabel(File Name:);private JLabel Label_Size=new JLabel(File Size:);private JLabel Label_BlockSize=new JLabel(Block Size:);private JLabel Label_Number= new JLabel(Number of Block:);private JLabel Label_TargetFile=new JLabel(Target File:);private JLabel Label_KB=new JLabel(KB);/文本域private JTextField Text_FileName=new JTextField();private JTextField Text_SizeOfFile=new JTextField();private JTextField Text_Number=new JTextField() ;private JTextField Text_Target=new JTextField();private JTextField Text_SelfSize=new JTextField();/按钮private JButton Button_BrowseFile=new JButton(.);private JButton Button_Target=new JButton(.);private JButton Button_Start=new JButton(Start Cutting);/单选Radioprivate ButtonGroup Buttons_Size=new ButtonGroup();private JRadioButton Radio_1_44M=new JRadioButton(1.44MB);private JRadioButton Radio_1_20M=new JRadioButton(1.2MB);private JRadioButton Radio_720K=new JRadioButton(720KB);private JRadioButton Radio_360K=new JRadioButton(360KB);private JRadioButton Radio_self=new JRadioButton(Self Defined);public CutPanel(int Height,int Width)/分割面板构造setLayout(null);int y=Height/32; int x=Width/32; /浏览文件按钮添加监听器 Button_BrowseFile.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) FileName=ShowOpenDialog.ChooseFile(true,false).get(0); if(FileName!=) Text_FileName.setText(FileName); FileSize=(int) (new File(FileName).length()/1024); Text_SizeOfFile.setText(+FileSize+ KB); if(Size!=0) Number=FileSize/Size; if(NumberFileSize) return 1; else if(FileSize%Size0) return (FileSize/Size)+1; else return FileSize/Size; /Start按钮添加监听器class CutStart implements ActionListenerpublic void actionPerformed(ActionEvent event)RunCut aThread=new RunCut();aThread.start();/多线程class RunCut extends Thread public void run()Size=Size*1024;byte Bytes=new byteSize; RandomAccessFile toWrite; int i=1; if(FileName!=&Target!=) try int temp = 0; RandomAccessFile raf=new RandomAccessFile(FileName,r); String Name=GetName(FileName); while( (temp = raf.read(Bytes)!=-1)/对文件分割 if(i10) toWrite=new RandomAccessFile(Target+/000+i+_+Name,rw); toWrite.write(Bytes, 0, temp); System.out.println(i=+i); CutProgressBar.setValue(int)(double)i/(double)Number)*100); toWrite.close(); i+; else toWrite=new RandomAccessFile(Target+/00+i+_+Name,rw); toWrite.write(Bytes, 0, temp); System.out.println(i=+i); CutProgressBar.setValue(int)(double)i/(double)Number)*100); toWrite.close(); i+; raf.close(); catch (IOException e) e.printStackTrace(); /返回文件路径中的文件名部分 public String GetName(String FileName)File tempFile=new File(FileName);System.out.println(tempFile.getName();return tempFile.getName(); class MergePanel extends JPanel private int Number;private String FileName=;private String TargetFile=E:temptemp;private ArrayList FileNames=new ArrayList();private ArrayList Temp=new ArrayList();/进度条private JProgressBar MergeProgressBar=new JProgressBar();/列表private DefaultListModel ListModel=new DefaultListModel();private JList List_Files=new JList(ListModel);private JScrollPane aScrollPane=new JScrollPane(List_Files,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);/文本private JTextField Text_FileName=new JTextField();private JTextField Text_Numbers=new JTextField();private JTextField Text_TargetFile=new JTextField(); /按钮private JButton Button_BrowseFile=new JButton(.);private JButton Button_Remove=new JButton(Remove);private JButton Button_Clear=new JButton(Clear);private JButton Button_StartMerge= new JButton(Start Merging);private JButton Button_Target=new JButton(.);/标签private JLabel Label_FileName=new JLabel(File Name:);private JLabel Label_FilesMerged=new JLabel(Files To Be Merged);private JLabel Label_Numbers=new JLabel(Numbers Of Files:);private JLabel Label_TargetFile=new JLabel(Target File:);/合并面板public MergePanel(int Height,int Weight) setLayout(null); int y=Height/32; int x=Weight/32; Text_FileName.setEditable(false); Text_Numbers.setEditable(false); Text_TargetFile.setEditable(false); /设置进度条 MergeProgressBar.setStringPainted(true); /设置位置 Label_FileName.setBounds(1*x,y,5*x,y); Label_FilesMerged.setBounds(1*x,3*y,10*x,y); Label_Numbers.setBounds(1*x,11*y,8*x,y); Label_TargetFile.setBounds(1*x,15*y,8*x,y); /List_Files.setBounds(1*x,4*y,29*x,6*y); /aScrollPane.setBounds(29*x)+(x/3),4*y,2*(x/3),6*y); aScrollPane.setBounds(1*x,4*y,29*x,6*y); Text_FileName.setBounds(6*x,y,18*x,y); Text_Numbers.setBounds(9*x,11*y,5*x,y); Text_TargetFile.setBounds(7*x,15*y,17*x,y); Button_BrowseFile.setBounds(25*x,y,5*x,y); Button_Remove.setBounds(9*x,13*y,6*x,y); Button_Clear.setBounds(16*x,13*y,6*x,y); Button_StartMerge.setBounds(1*x,17*y,8*x,y); Button_Target.setBounds(25*x,15*y,5*x,y); MergeProgressBar.setBounds(10*x,17*y,20*x,y); /添加组件 /add(List_Files); add(aScrollPane); add(Text_FileName); add(Text_Numbers); add(Text_TargetFile); add(Label_FileName); add(Label_FilesMerged); add(Label_Numbers); add(Label_TargetFile); add(Button_BrowseFile); add(Button_Remove); add(Button_Clear); add(Button_Target); add(Button_StartMerge); add(MergeProgressBar); /选择目标文件夹按钮监听器 Button_Target.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) String temp=ShowOpenDialog.ChooseFile(false, false).get(0); if(temp!=) TargetFile=temp; Text_TargetFile.setText(TargetFile); ); /选择文件按钮监听器 Button_BrowseFile.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) Temp=ShowOpenDialog.ChooseFile(true,true); if(Temp.get(0)!=) /FileName=; int x=0; for(String a:Temp) FileName += a; ListModel.addElement(a); FileNames.add(a); x+; Text_FileName.setText(FileName); Number=Number+x; Text_Numbers.setText(+Number); ); /清空按钮添加监听器 Button_Clear.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) ListModel.clear(); FileNames.clear(); Number=0; Text_FileName.setText(); Text_Numbers.setText(+Number); ); /移除按钮添加监听器 Button_Remove.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) int index=List_Files.getSelectedIndex(); if(index=0&index=ListModel.size() ListModel.remove(index); FileNames.remove(index); Number-; for(String a:FileNames) FileName += a; Text_FileName.setText(FileName); /index=Integer.parseInt(Text_Numbers.getText(); /if(index!=0) / Text_Numbers.setText(Number+); / ); Button_StartMerge.addActionListener(new MergeStart(); /Start按钮监听器class MergeStart implements ActionListenerpublic void actionPerformed(ActionEvent event)RunMerge bThread=new RunMerge();bThread.start();/实现多线程class RunMerge extends Threadpublic void run()RandomAccessFile reader;RandomAccessFile writter;int i=FileNames.size();int j=0;try writter=new RandomAccessFile(TargetFile+/+GetName(FileNames.get(0),rw);for(String name:FileNames)/文件读写System.out.println(name);tryreader=new RandomAccessFile(name,r);byte Bytes=new byte(int)reader.length();reader.read(Bytes);writter.seek(writter.length();writter.write(Bytes);reader.close();j+; System.out.println(J=+j);MergeProgressBar.setValue(int)(double)j/(double)i)*100); catch (FileNotFoundException e) e.printStackTrace(); catch (IOException e) e.printStackTrace();writter.close(); catch (FileNotFoundException e1) e1.printStackTrace();
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 乳制品健康宣传活动创新创业项目商业计划书
- 电商平台用户画像深度挖掘创新创业项目商业计划书
- 老年婚恋交友平台创新创业项目商业计划书
- 线上购物线下试妆创新创业项目商业计划书
- 水利工程维修养护数字孪生管理创新创业项目商业计划书
- 电商供应链可视化管理系统创新创业项目商业计划书
- 汽车赛事直播服务创新创业项目商业计划书
- 辐射核安全知识培训内容课件
- 2025年数字货币对货币政策传导机制影响的金融科技视角研究
- 2025年文化与科技融合趋势下的数字文化内容创作创新模式研究报告
- 2023年山东水发集团有限公司招聘笔试题库及答案解析
- 全国2023年招商银行招银网络科技校园招聘考试模拟卷3套含答案详解
- YY/T 1745-2021自动粪便分析仪
- MT 220-1990煤矿用防爆柴油机械排气中一氧化碳、氮氧化物检验规范
- 燕窝工艺参考
- 班组施工任务单
- 斜拉桥主桥索塔施工监理实施细则
- 钢结构模块化安装施工方案
- 双氧水生产工艺简单简介
- KNS机器参数,干货
- 医院输血科技术人员绩效考核指标
评论
0/150
提交评论