CSC 551: Web Programming
Spring 2001

HW4: Java Applet Programming

The Histogram class defines an applet for drawing histograms in a Web page. The idea is to have the user enter data in a textarea and then submit that data to the Histogram applet. The applet code will then parse the data and display the corresponding histogram. For example,

Part 1

Copy the source for the Histogram class into a file named and compile it into byte code. Then create a Web page to serve as an interface for this applet.

To create and compile an applet using Visual J++, perform the following steps:

  1. Select Microsoft Visual J++ from the Programs Menu.
  2. A window titled "New Project" will appear. Select "Applet on HTML" under the "Web Pages" option in order to create a new applet project, and enter the name Histogram in the project name box. Also, enter the desired folder for storing the applet project, then hit the "Open" button.
  3. This will create a prject with default files "" and "Page1.html". The first thing you must do is change the names of these files. Click on the + that appears in the Project Explorer window at the upper right. Then right click on each of the files and select rename to change the names to "" and "Histogram.html".
  4. You can then cut-and-paste the code for the Histogram class into the file.
  5. To compile the applet, select "Build" under the Build menu.

Part 2

Modify the applet code so that the bars of the histogram alternate colors. For example, the first bar might be yellow, the second bar green, then yellow, then green, etc.

Part 3

Modify the applet code so that the bars of the histogram are normalized to fit in the applet window. That is, the lengths of the bar should be scaled so that the longest bar reaches the entire width of the applet, and the heights of the bars should be scaled to fill the entire height.