Owl Sams Teach Yourself Java 2 in 21 Days

Day 10: Adding Images, Animation, and Sound

NOTES AND CORRECTIONS

  • On Page 244, two statements showing how to load an image in an applet are incorrect. The code new URL should be replaced with getImage, which turns the two statements into the following:
    • Image img = getImage(getDocumentBase(), "book.gif");
    • Image img = getImage(getDocumentBase(), "images/book.gif");
  • On Page 260, line 17 of Listing 10.5 has a semi-colon that should be deleted. The correct line is the following:
    • if (runner == null) {

SOURCE FILES

READER QUESTIONS

  • Q: Pg. 244 states, "Choosing between getDocumentBase() or getCodebase() depends on whether your images are stored in subfolders of your Java applet or subfolders of the applet's Web page." Since on pg. 247 we create a subfolder for the images I would have expected the Fillmore.java and Neko.java to use getDocumentBase() instead of getCodeBase(). Did I misunderstand? -- R.M.
    A:
    The difference between getDocumentBase() and getCodeBase() only matters when the applet's Java class is stored in a different folder than the Web page that contains the applet. Because Fillmore.class and Fillmore.html are both stored in \J21work, you can use either method call and get the same result.

LINKS