-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
33 lines (28 loc) · 946 Bytes
/
Main.java
File metadata and controls
33 lines (28 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import javax.swing.*;
import java.io.*;
/**
* Main method gets file from user and applies to huffman tree
*
* @author Cathal Mullen
* @version 12/3/2019
*/
public class Main
{
public static void main(String[] args) throws IOException, FileNotFoundException {
String s = "";
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
s = selectedFile.getName();
System.out.println("Selected file: " + selectedFile.getAbsolutePath());
}
HuffmanCoding hf = new HuffmanCoding(s);
hf.encodeMsg();
hf.showTable();
hf.displayTree();
hf.numBits();
hf.decode();
}
}