CSC 551: Web Programming
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,
Copy the source for the Histogram class into a file named Histogram.java 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:
- Select Microsoft Visual J++ from the Programs Menu.
- 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.
- This will create a prject with default files "Applet1.java" 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 "Histogram.java" and "Histogram.html".
- You can then cut-and-paste the code for the Histogram class into the Histogram.java file.
- To compile the applet, select "Build" under the Build menu.
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.
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.