This project implements a Huffman Coding algorithm to compress and decompress text. The application includes a user-friendly Graphical User Interface (GUI) built with Java Swing, providing features for encoding strings, visualizing the Huffman tree, and analyzing the efficiency of the compression.
Huffman Coding is a lossless data compression algorithm that uses variable-length binary codes to represent characters, optimizing the storage of text by assigning shorter codes to more frequently used characters.
- Encoding: Converts a given string into its Huffman-encoded binary representation.
- Decoding: Reconstructs the original string from the encoded binary sequence.
- Tree Visualization: Displays the Huffman tree structure used for encoding.
- Efficiency Analysis: Calculates and displays metrics such as:
- ASCII bit usage
- Huffman bit usage
- Bit reduction
- Compression efficiency percentage
- Input field for entering text to encode.
- Panels to display encoded and decoded text.
- A dedicated section for efficiency metrics.
- Interactive visualization of the Huffman tree.
- Main.java: The main entry point of the program. It initializes the GUI, handles user input, and coordinates encoding, decoding, and tree visualization.
- HuffmanCoder.java: Implements the Huffman Coding algorithm. Handles tree construction, encoding, and decoding logic.
- Heap.java: A min-heap implementation used as a priority queue for constructing the Huffman tree.
- TreePanel.java: A custom Swing component for drawing the Huffman tree in the GUI.
- Java Runtime Environment (JRE) 8 or later.
- Java Development Kit (JDK) 8 or later.
- A build tool like
javac
or an IDE (e.g., IntelliJ IDEA, Eclipse).
-
Open your terminal and clone the repository:
git clone https://github.com/eizadhamdan/huffman_coding_project.git
-
Navigate into the project directory:
cd huffman_coding_project
- Download the
.jar
file. - Run the program by double-clicking the
.jar
file or using the terminal:java -jar HuffmanApp.jar
- Compile the source files:
javac *.java
- Run the program:
java Main
- Input: Enter a string in the input field.
- Encode: Click the "Encode" button to compress the string.
- Output:
- Encoded binary string
- Decoded original string
- Efficiency analysis (bits saved and compression ratio)
- Visualization: View the Huffman tree structure in the tree panel.