1010import javax .swing .JOptionPane ;
1111import javax .swing .JPanel ;
1212
13- import prog .huffman .Hzipping ;
14- import prog .huffman .Hunzipping ;
15- import prog .lzw .Lzipping ;
16- import prog .lzw .Lunzipping ;
13+ import prog .huffman .HuffmanCompressor ;
14+ import prog .huffman .HuffmanDecompressor ;
15+ import prog .lzw .LzwCompressor ;
16+ import prog .lzw .LzwDecompressor ;
1717
1818public class Main extends JFrame implements ActionListener {
1919 // Definition of global values and items that are part of the GUI.
2020
21- static public File opened_file , other_file ;
22- static long past , future ;
23- static JLabel redLabel , blueLabel , redScore , blueScore ;
21+ static public File openedFile , outputFile ;
22+ static long originalSize , compressedSize ;
23+ static JLabel originalSizeLabel , compressedSizeLabel , originalSizeValue , compressedSizeValue ;
2424 static JPanel buttonPanel , titlePanel , scorePanel ;
25- static JButton ZH , UH , ZL , UL , EX ;
25+ static JButton huffmanCompressButton , huffmanDecompressButton , lzwCompressButton , lzwDecompressButton , exitButton ;
2626
2727 public JPanel createContentPane () {
2828 return MainPanel .createContentPane (this );
2929 }
3030
3131 private void handleHuffmanCompression () {
32- Hzipping . beginHzipping ( opened_file .getPath ());
32+ HuffmanCompressor . beginHuffmanCompression ( openedFile .getPath ());
3333 showCompressionCompleteDialog ("Zipping" );
3434 updateFileStats (".huffz" );
3535 }
3636
3737 private void handleHuffmanDecompression () {
38- Hunzipping . beginHunzipping ( opened_file .getPath ());
38+ HuffmanDecompressor . beginHuffmanDecompression ( openedFile .getPath ());
3939 showCompressionCompleteDialog ("UnZipping" );
4040 updateDecompressionStats ();
4141 }
4242
4343 private void handleLZWCompression () {
44- Lzipping . beginLzipping ( opened_file .getPath ());
44+ LzwCompressor . beginLzwCompression ( openedFile .getPath ());
4545 showCompressionCompleteDialog ("Zipping" );
4646 updateFileStats (".LmZWp" );
4747 }
4848
4949 private void handleLZWDecompression () {
50- Lunzipping . beginLunzipping ( opened_file .getPath ());
50+ LzwDecompressor . beginLzwDecompression ( openedFile .getPath ());
5151 showCompressionCompleteDialog ("UnZipping" );
5252 updateDecompressionStats ();
5353 }
@@ -59,31 +59,31 @@ private void showCompressionCompleteDialog(String operation) {
5959 }
6060
6161 private void updateFileStats (String extension ) {
62- redScore .setText (opened_file .length () + "Bytes" );
63- other_file = new File (opened_file .getPath () + extension );
64- future = other_file .length ();
65- blueScore .setText (future + "Bytes" );
62+ originalSizeValue .setText (openedFile .length () + "Bytes" );
63+ outputFile = new File (openedFile .getPath () + extension );
64+ compressedSize = outputFile .length ();
65+ compressedSizeValue .setText (compressedSize + "Bytes" );
6666 }
6767
6868 private void updateDecompressionStats () {
69- redScore .setText (opened_file .length () + "Bytes" );
70- String s = opened_file .getPath ();
69+ originalSizeValue .setText (openedFile .length () + "Bytes" );
70+ String s = openedFile .getPath ();
7171 s = s .substring (0 , s .length () - 6 );
72- other_file = new File (s );
73- future = other_file .length ();
74- blueScore .setText (future + "Bytes" );
72+ outputFile = new File (s );
73+ compressedSize = outputFile .length ();
74+ compressedSizeValue .setText (compressedSize + "Bytes" );
7575 }
7676
7777 public void actionPerformed (ActionEvent e ) {
78- if (e .getSource () == ZH ) {
78+ if (e .getSource () == huffmanCompressButton ) {
7979 handleHuffmanCompression ();
80- } else if (e .getSource () == UH ) {
80+ } else if (e .getSource () == huffmanDecompressButton ) {
8181 handleHuffmanDecompression ();
82- } else if (e .getSource () == ZL ) {
82+ } else if (e .getSource () == lzwCompressButton ) {
8383 handleLZWCompression ();
84- } else if (e .getSource () == UL ) {
84+ } else if (e .getSource () == lzwDecompressButton ) {
8585 handleLZWDecompression ();
86- } else if (e .getSource () == EX ) {
86+ } else if (e .getSource () == exitButton ) {
8787 System .exit (0 );
8888 }
8989 }
0 commit comments