// Template provided by Paul Amer for use in Project 3 // of CISC451/561: Data Compression for Multimedia // This applet opens a text window and echos the contents // of an ASCII file in that window. Students must complete // this template with their code for decoding amerRLE encoded // files. import java.net.*; import java.io.*; import java.applet.Applet; import java.awt.*; // Abstract Windowing Toolkit package is imported. public class EchoApplet extends Applet { private String filename; private TextArea outputArea; public void init () // init invoked automatically by browser. { outputArea = new TextArea(15, 65); // rows, columns outputArea.setEditable(false); // make applet read-only outputArea.setFont(new Font("Courier", Font.PLAIN, 12)); // fixed-width font add(outputArea); // show empty text area in applet try { // file to be decoded should be a param in the html file // if param doesn't exist the html file, give error message filename = getParameter("FileToBeEchoed"); if (filename == null) { outputArea.append("Error: parameter FileToBeEchoed missing in html file"); return; } // create http connection to later get compressed file URL ourURLConnection = new URL(filename); // open the stream to be used for downloading the compressed file DataInputStream inFile = new DataInputStream(ourURLConnection.openStream()); // STUDENTS: You will need to replace the following loop with // a call to a method that decodes and outputs the compressed input file // read and echo each character until EOF int inputChar; while ((inputChar = inFile.read()) != -1) { outputArea.append(String.valueOf((char)inputChar)); } inFile.close(); } catch (Exception e) { e.printStackTrace(); } } }