[CMU logo]

90-726

Java in Electronic Community Development

H. John Heinz III School of Public Policy and Management

Assignment 1: Introduction to Applets

Summary

Create an applet that simplifies web page design by drawing bar graphs. The web page author includes the parameters of the graph in the HTML code, such as size, labels, and data values. The java applet is responsible for displaying the data in an accurate and easy-to-understand manner.

Sample HTML excerpt

<applet
  code=BarGraph.class
  align=top
  width=300
  height=200 >
  <param name=numItems value=3>
  <param name=foreground value=000000>
  <param name=background value=ffffff>
  <param name=barWidth value=25>
  <param name=gapWidth value=15>
  <param name=dataMin value=1.25>
  <param name=dataMax value=2.0>
  <param name=numTicks value=6>
  <param name=hpad value=40>
  <param name=vpad value=20>

  <param name=color1 value=ff0000>
  <param name=height1 value=1.5>
  <param name=label1 value="1993">

  <param name=color2 value=808000>
  <param name=height2 value=1.67>
  <param name=label2 value="1994">

  <param name=color3 value=00ff00>
  <param name=height3 value=1.75>
  <param name=label3 value="1995">
</applet>

Parameters

The parameters in the above HTML file affect the graph in the following ways.

Notes

Normally, an applet should perform some basic error handling. For instance, the Integer.parseInt method (see below) throws a NumberFormatException which should be caught. However, as this is the first assignment, and since this applet is not interactive, you do not need to use any try, catch, finally syntax in your code. See Nutshell pp. 40-45 if you are interested. (You will need to know this later.)

Tips

Extras

The above assignment represents the minimal work necessary to pass. For full credit, implement one or two of the following enhancements, or invent your own. (The following are only suggestions.) Make whatever design decisions necessary, including new parameter names and reasonable defaults. Be sure that the enhanced applet still supports the basic parameters. Decide whether to extend the original applet, or create a new one or ones. Describe the enhancements, and create HTML files that show them off.

  1. Add axis labels on the vertical and horizontal axes. Try to print the vertical label vertically.
  2. Add support for different fonts. Try to make the font support be platform independent.
  3. Improve the axis labelling, so that it does center justification on the horizontal and right justification on the vertical.
  4. When dataMin is negative and dataMax is positive, allow the bars to be drawn relative to 0.
  5. Allow the data to be shown as a pie chart instead of a bar graph.
  6. For large datasets, include an alternate parameter interface that is more compact.

Questions

In addition to writing code, briefly answer the following questions in a separate file, about 1 paragraph each (see the "Submissions" page).

  1. How is Java different from traditional compiled languages such as C? How does this affect its current uses? How is Java expected to be useful in the future?
  2. Why is a client/server model useful? What are its advantages and disadvantages over mainframe systems and LANs?