Owl Sams Teach Yourself Java 2 in 21 Days Professional Reference Edition
/ YESTERDAY / TOMORROW

Day 9: Making Programs Look Good with Graphics, Fonts, and Color

NOTES AND CORRECTIONS

  • On Page 226 in the section on drawing arcs, it states that "the number of degrees traveled by the arc is specified in a clockwise direction by using positive numbers. This is the opposite of the way a non-2D arc is handled." This is true of beta versions of JDK 1.2, but was corrected for the final release. The number of degrees traveled is specified in a counterclockwise direction.
  • In Listing 9.5, Lines 15-16, if you're not using a beta version of JDK 1.2, one of the arguments should be changed from 180 to -180 so that the arcs look like ocean waves and match Figure 9.17. The correct lines are the following:
    • Arc2D.Float wave = new Arc2D.Float(ax, ay,
          10, 10, 0, -180, Arc2D.OPEN);
     

SOURCE FILES

READER QUESTIONS

  • Q: I am confused by what the lowercase "f" is referring to in Day 9 on page 227 and elsewhere in the chapter. It is added to coordinates, as in the polly method polly.moveTo(5f, 0f). Why is the "f" used for these coordinates and not those for the arc on page 226, and why is a capital "F" used elsewhere, such as the fl method fl.moveTo(10F, 12F)? Help me with all these Fs and fs!
    A: The F and f indicate that a number is a floating-point number rather than an integer, and they can be used interchangeably. If you don't use one of them, the Java compiler will assume that the number is an int value. Many methods and constructors in Java require floating-point arguments but can handle integers, because an integer can be converted to floating-point without changing its value. For this reason, constructors like Arc2D.Float() on Page 226 can use arguments such as 10 and 180 instead of 10F and 180F.
  • Q: The Map2D applet compiles and can be run within appletviewer, but it won't run in either the current Netscape Navigator or Microsoft Internet Explorer. Why is this the case when other applets will run?
    A:
      Map2D won't run outside of appletviewer because it's one of several applets in the book that requires a Java 1.2-capable browser. Neither Navigator nor Internet Explorer supports 1.2 fully at this time, so Sun has developed a Java Plug-in that enhances their built-in Java support.
    The Plug-in is a Java interpreter that can be used as an alternative to the Java interpreters included with Navigator and Internet Explorer. A Java programmer uses a modified <APPLET> tag to make the Java Plug-in run the applet if the plug-in is present on a user's system (if not, the plug-in can be immediately installed).
    Sun has created an HTML Converter that will read an .html file containing applets and convert the HTML so that the applets use the Java Plug-in.
    None of the book's .html files have been modified to call the Java Plug-in, so they're being added to this Web site as time permits. The first example is Map2D_plugin.html.