The first bold line of the following listing begins a block that defines theHelloWorldclass.import javax.swing.JApplet; import java.awt.Graphics; public class HelloWorld extends JApplet { public void paint(Graphics g) { g.drawRect(0, 0, getSize().width - 1, getSize().height - 1); g.drawString("Hello world!", 5, 15); } }Applets inherit a great deal of functionality from the
AppletorJAppletclass, including abilities to communicate with the browser and present a graphical user interface (GUI) to the user.An applet which will be using GUI components from Swing (Java's GUI toolkit) should extend the
javax.swing.JAppletbase class, which provides the best integration with Swing's GUI facilities.
JAppletprovides the same "RootPane" top-level component structure as Swing'sJFrameandJDialogcomponents, whereasAppletprovides just a simple panel. See How to Use Root Panesfor more details on how to utilize this feature.An applet may extend
java.applet.Appletwhen it makes no use of Swing's GUI components. This may be the case if the applet does all its own rendering using the Java graphics libraries (such as with graphing or gaming) and/or uses only AWT components.