Chapter 11

The exercises here are taken from my forthcoming book The Java Developer's Resource.

Quiz

  1. What happens if you try to draw objects at negative coordinates? e.g. g.drawLine(-5, -4, 64, 50)?
  2. What's the difference between g.drawLine(0, 1, 5, 6) and g.drawLine(5, 6, 0, 1)?
  3. What's the difference between g.drawLine(0, 1, 5, 6) and g.drawLine(1, 0, 6, 5)?

Exercises

  1. Modify the WrapText applet so that it optionally accepts FONT, SIZE and STYLE PARAMs which set the font face, point size and style in which the String is drawn. Be sure to gracefully handle the case when the APPLET tag does not include any or all of these PARAMs or includes invalid values (e.g. STYLE="UNDERLINE").
  2. The default StringTokenizer used by the WrapText applet breaks words on white space, i.e. spaces, tabs, newlines and carriage returns. Make it more intelligent about choosing line breaks. In particular let it break a line on a hyphen and have it jump to the next line (i.e. end a paragraph) on a newline or a carriage return. To do this you'll need to use a different StringTokenizer constructor, specifically StringTokenizer(String s, String delimiters) where s is the String to tokenize and delimiters is a String that contains all the characters you want to break on.
  3. If the String won't fit in the applet, even after breaking into pieces, shrink the font size so that it does fit. What's the smallest font size you can use?
  4. Add labeled coordinate axes to the SineApplet graph. Make sure they adjust if the applet is resized.
  5. Modify the SineApplet so that it looks for xmin, xmax, ymin, and ymax to be specified via parameters. However for robustness if the author of the HTML forgets to specify them, supply some reasonable default values. You will probably need to make these member variables rather than local variables.


[ Exercises | Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
Last Modified August 20, 1996