9.2. Creating an Applet

Creating an applet involves two steps: making the Java class and making the associated HTML document. The Java class defines the actual behavior of the applet, and the HTML document associates the applet with a particular rectangular region of the Web page.

Template for Applets

Listing 9.1 shows the typical organization of an applet. It contains a section for declaring instance variables, an init method, and a paint method. The init method is automatically called by the browser when the applet is first created. Then, when the applet is ready to be drawn, paint is called. The paint method is automatically called again whenever the image has been obscured and is reexposed or when graphical components are added, or the method ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.