Percent of done project

99 views Asked by At

I have an assignment regarding Java NIO and Thread. I should write a program with these four important abilities: copy, cut, rename, and delete. I made 4 classes for each part of project. All of them extend Runnable and in the run I used some code like this:

fc = new JFileChooser();
fc.showOpenDialog(Copy.this);
File f1 = fc.getSelectedFile();
fc.showOpenDialog(Copy.this);
File f2 = fc.getSelectedFile();
if(copyFile(f1, f2)){
    System.out.println("File Copied");
}

fc is a JFileChooser class field and I have a mainFrame that have 4 buttons and each one starts a threat from each class. I do not know about my way and I have no idea what it should be like. I've watched two videos about multi-threading and I have no idea how this program can be a deadlock or how it can have problems running, and my biggest problem is that I want to have JProgressBar in file copying, file deleting and file cutting and I have no idea about how can I know about these levels in the program to do the best with JProgressBar. it is the whole project : https://www.mediafire.com/?yyw8jg1xncfp2xn

1

There are 1 answers

1
AudioBubble On BEST ANSWER

To obtain the values needed to update your JProgressBar the simplest way would be to have a thread monitor the size of your target files and compare them against the original. you could do this with f1.length() and f2.length(). by comparing these 2 values, you would be able to determine the status of the current action whether it is deleting, copying, or truncating the size of a file. alternatively, you would need to have a handle to your JProgressBar within each of your functions such as copyFile(...) and from there you could update the progress bar based on the iteration within the loop. For a more detailed answer, I would need to see the rest of the code.