There are questions that need to be answered. Please answer it with the best of your abilities. Those are the pictures I attached below. There are 2 class files that need to be completed. I will provide them for you and please code in Java, as well as read the instructions in the pictures to understand the assignment. The 2 class files will be below this.
import java.io.File;
public class ZipFile
{
private ArrayList<String> fileList;
private String outputFile;
private String srcPath;
private File file;
public ZipFile(File file)
{
fileList = new ArrayList<String>();
// TODO
}
public void fillFileList(File f)
{
if (f.isFile())
{
String currFilePath = f.getAbsoluteFile().toString();
String relativeFilePath;
if (this.srcPath.length() < currFilePath.length())
relativeFilePath = currFilePath.substring(this.srcPath.length() + 1, currFilePath.length());
else
relativeFilePath = currFilePath.substring(this.srcPath.length(), currFilePath.length());
fileList.add(relativeFilePath);
}
if (f.isDirectory())
{
// TODO
}
}
public void makeZip(File dir)
{
// TODO
}
}
Zipper Required Code:
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import java.util.*;
import java.util.zip.*;
import java.io.*;
public final class Zipper extends Application
{
private Desktop desktop = Desktop.getDesktop();
@Override
public void start(final Stage stage)
{
stage.setTitle("File Chooser");
final FileChooser fileChooser = new FileChooser();
final DirectoryChooser directoryChooser = new DirectoryChooser();
final Button openFileButton = new Button("Select File");
final Button openDirectoryButton = new Button("Select Directory");
openFileButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(final ActionEvent e)
{
File src = fileChooser.showOpenDialog(null);
if (src != null)
createZip(src);
else
System.out.println("No File Selected.");
}
});
openDirectoryButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(final ActionEvent e)
{
File src = directoryChooser.showDialog(null);
if (src != null)
createZip(src);
else
System.out.println("No Directory Selected.");
}
});
final GridPane inputGridPane = new GridPane();
GridPane.setConstraints(openFileButton, 0, 0);
GridPane.setConstraints(openDirectoryButton, 1, 0);
inputGridPane.setHgap(6);
inputGridPane.setVgap(6);
inputGridPane.getChildren().addAll(openFileButton, openDirectoryButton);
final Pane rootGroup = new VBox(12);
rootGroup.getChildren().addAll(inputGridPane);
rootGroup.setPadding(new Insets(12, 12, 12, 12));
stage.setScene(new Scene(rootGroup));
stage.show();
}
private static void createZip(File src)
{
// TODO
}
public static void main(String[] args) {
Application.launch(args);
}
}


0 comments