Assignment #5
Due: Monday, October 12, 1998
Using Applet "parameters" and Font Metrics

When you have successfully completed this assignment, I shouldbe able to insert the following "applet" and associated "param" tag(s) into an html file (substituting YOUR logon id for "userid" in the codebase) and have it produce the scalable box/oval/message shown at the bottom of this assignment page.
   <applet code=assign5.class codebase=/phys2411/userid 
           width=500 height=500›
      <param name="message"   value="This should be CENTERED!"›
      <param name="boxWidth"  value="250"›
      <param name="boxHeight" value="350"›
      <param name="fontSize"  value="14"›
   <applet›

These parameters represent:

  • boxWidth = the width of the rectangle;
  • boxHeight = the height of the rectangle;
  • fontSize = the size of the font that is used to type the "message";
  • message = ANY arbitrary message.

With these variable parameters inserted in an html file, ANY user should be able to use your "assign5.class" Java-byte code to draw a rectangle of arbitrary width and arbitrary height (with an embedded oval and black diagonal line, as in assignment #4) AND print an arbitrary message just below the rectangle that is centered along the bottom of the rectangle (as illustrated below).

In order to successfully develop the java code that satisfies the "scalability" requirements specified above, you may find it useful to follow these suggestions:
  • Don't start from scratch! Build upon the java code that you developed in connection with this past week's "assignment #4."

  • Copy the following html file into your own directory and play with its "param" values in order to understand completely what degree of scalability I'm looking for. (As you will see, this html file executes the "assign5.class" Java-byte code that I created. The object is to develop your own Java program that produces very similar results to this one of mine!)

    /wwwdb/htdocs/faculty/tohline/PHYS2411/q2.dir/assign5.html

  • In addition to the "java.awt.*" and "java.applet.*" libraries, you will have to import the "java.lang.*" library in order for the applet "param" arguments to work.

  • In order to successfully center the message at the bottom of the rectangle, you will need to create a "FontMetrics" object and utilize the "stringWidth" method that is built into the FontMetrics class. (See pp. 480-483 of our "Exploring Java" textbook.)

  • For simplicity, I want you to FIX the upper, left-hand corner of rectangle at the (x,y) position (10,10).

  • Inside all of the java programs that I have asked you to construct, to date, you have developed only one "method" --- the "paint()" method. In order to complete this new assignment, you will have to add one additional "method" to your program --- an "init()" method. Within the "init()" method, you should use the "getParameter" method to read in the "param" values that a user specifies in his/her html "applet". [To see how this is done, look at the "Exam1.java" program that I handed out to you during class on Friday, 2 October. This same program is available through the "Java source code" that I asked you to link to your first exam.]

Like this:
You'll see this instead of graphics if your browser does not
        understand Java.