import javafx.stage.FileChooser;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class ZipInterface extends JFrame{
public ZipInterface(){
this.setLayout(null);
this.setTitle("新建压缩文件");
setVisible(true);
Container container = this.getContentPane();
setBounds(470,210,982,614);
container.setBackground(new Color(240, 240, 240));
//----------文件列表-------------
String[][] datas = {};
String[] titles = {"名称","文件路径"};
DefaultTableModel model = new DefaultTableModel(datas, titles);
JTable table = new JTable(model);
JButton addButton = new JButton("添加");
addButton.setBounds(705,378,125,32);
JButton delButton = new JButton("删除");
delButton.setBounds(845,378,125,32);
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//------------文件选择器-------------
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jFileChooser.setMultiSelectionEnabled(true);
jFileChooser.showDialog(new JFrame(),"选择");
File[] files = jFileChooser.getSelectedFiles();
for(File file:files){
model.addRow(new String[]{file.getName(),file.getAbsolutePath()});
}
}
});
delButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();
model.removeRow(row);
}
});
table.setBackground(new Color(255, 255, 255));
JScrollPane jScrollPane = new JScrollPane(table);
jScrollPane.setBounds(13,88,952,227);
container.add(jScrollPane);
container.add(addButton);
container.add(delButton);
//----------添加标签--------
JLabel jLabel = new JLabel("压缩文件设置");
jLabel.setFont(new Font("微软雅黑",Font.BOLD,13));
jLabel.setBounds(10,428,150,15);
container.add(jLabel);
JLabel jLabel1 = new JLabel("压缩文件名");
jLabel1.setBounds(10,466,150,32);
container.add(jLabel1);
JTextField jTextField = new JTextField();
jTextField.setText("D://Untitled.zip");
jTextField.setBounds(176,474,649,28);
container.add(jTextField);
//------------------浏览Button-----------------
JButton browseButton = new JButton("浏览");
browseButton.setBounds(844,474,125,32);
browseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//----------文件选择器-------
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
jFileChooser.showDialog(new JFrame(),"选择");
File Dir = jFileChooser.getSelectedFile();
jTextField.setText(Dir.getAbsolutePath()+"\\新建压缩.zip");
}
});
container.add(browseButton);
//---------开始和取消----------
JButton startjButton = new JButton("开始");
startjButton.setBounds(689,530,125,32);
startjButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//-----开始压缩------
//压缩前的准备工作
int rows = table.getRowCount();
String sourceFilePath;
if(rows == 0){
new DialogDemo("操作错误");
}
else if(rows == 1){
String targetPath = jTextField.getText();
String sourcePath = table.getValueAt(0,1).toString();
try {
new Compress(sourcePath,targetPath);
new DialogDemo("压缩成功");
} catch (IOException ex) {
new DialogDemo(ex.getMessage());
}
}
else{
int flag = 1;
// List<File> files = new ArrayList<>();
String DirPath = jTextField.getText().substring(0,jTextField.getText().lastIndexOf(".zip"));
File Dir = new File(DirPath);
if(Dir.exists()){
new RemoveFile(Dir);
}
Dir.mkdirs();
System.out.println(Dir.getAbsolutePath());
for(int i=0;i<rows;i++){
String path = table.getValueAt(i,1).toString();
// files.add(new File(path));
try {
new Filemv(path,DirPath);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
try {
new Compress(DirPath,jTextField.getText());
new RemoveFile(Dir);
new DialogDemo("压缩成功");
} catch (IOException ex) {
new DialogDemo(ex.getMessage());
throw new RuntimeException(ex);
}
}
}
});
JButton canceljButton = new JButton("取消");
canceljButton.setBounds(831,530,125,32);
canceljButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//-----关闭窗口----
dispose();
}
});
container.add(startjButton);
container.add(canceljButton);
this.setVisible(false);
this.setVisible(true);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
WinZip.zip (43个子文件)
FinalProduct.iml 433B
src
MainInterface.java 935B
Compress.java 2KB
MainMenu.java 107B
DialogDemo.java 425B
ZipButton.java 523B
UnzipButton.java 529B
Filemv.java 2KB
ZipInterface.java 6KB
RemoveFile.java 1KB
UnZipInterface.java 5KB
UnCompress.java 1KB
out
production
FinalProduct
UnZipInterface$4.class 2KB
MainInterface$1.class 645B
UnZipInterface$1.class 2KB
ZipButton.class 560B
Filemv.class 2KB
Compress.class 2KB
RemoveFile.class 1KB
ZipButton$1.class 658B
DialogDemo.class 797B
ZipInterface.class 3KB
ZipInterface$2.class 973B
UnZipInterface$5.class 655B
MainInterface.class 1KB
UnZipInterface$3.class 1KB
UnCompress.class 2KB
MainMenu.class 403B
UnZipInterface$2.class 985B
ZipInterface$3.class 1KB
UnzipButton.class 570B
ZipInterface$5.class 643B
UnzipButton$1.class 672B
ZipInterface$4.class 2KB
ZipInterface$1.class 2KB
UnZipInterface.class 3KB
.idea
.name 11B
uiDesigner.xml 9KB
workspace.xml 4KB
misc.xml 274B
modules.xml 271B
.gitignore 50B
.gitignore 344B
共 43 条
- 1
资源评论
小小星12304
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功