Main Applet Methods

Although an applet can have many methods, here are five main methods that you need to be aware of:

  • init()

  • start()

  • paint()

  • stop()

  • destroy()

The init() method is the place to put code that sets up the applet screen, such as adding Buttons or text fields or creating Image objects within limits. It is also the place to start the downloading of images through a separate thread using the MediaTracker class discussed later. Think of init() as analogous to a constructor. Applets do not have explicit constructors.

The start() method is where you initiate what must happen when a user goes to your applet's Web page. Here is a sample scenario. Five Web pages are up, one of which has your applet on it. At first, the user ...

Get PURE Java™ 2 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.