9.3. An Example Applet

Listing 9.3 presents an applet that follows the pattern shown in the previous section. The details of the various steps the applet performs are covered in later sections, but the basic approach is what is important here. The variable declaration section declares a variable of type Image. The init method sets the default color and font, loads an image file from the network and assigns it to the Image declared earlier, adds a label to the applet, then performs an informational printout. The paint method draws the image, placing its top 50 pixels from the top of the applet. Listing 9.4 shows the associated HTML document; the result in Internet Explorer 5.0 (Windows 2000) is shown in Figure 9-1.

Figure 9-1. Result of applet ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.