Sun Java Solaris Communities My SDN Account Join SDN
 
Code sample

Code Samples from the Java Developers Almanac 2000

 


Code Samples Index

These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms

The Quintessential Applet

Every applet must subclass Applet.

 import java.applet.*;
 import java.awt.*;
     
 public class BasicApplet extends Applet {
   public void init() {
     // Called once by the browser when 
     // it starts the applet.
   }
   public void start() {
     // Called whenever the page containing 
     // this applet is made visible.
   }
   public void stop() {
     // Called whenever the page containing this 
     // applet is not visible.
   }
   public void destroyed() {
     // Called once when the browser destroys 
     // this applet.
   }
   public void paint(Graphics g) {
     // Called whenever this applet needs to 
     // repaint itself.
   }
 }
 

This is the applet's accompanying HTML file.
 <applet code=BasicApplet width=100 height=100>
 </applet>
 

Examplets provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan.

Order this book from Amazon