The JApplet Class

JApplet is a simple extension of java.applet.Applet to use when creating Swing programs designed to be used in a web browser (or appletviewer). As a direct subclass of Applet, JApplet is used in much the same way, with the init( ), start( ), and stop( ) methods still playing critical roles. The primary thing JApplet provides that Applet does not is the use of a JRootPane as its single display component. The properties and methods described below should look a lot like those described in the previous sections on JFrame and JWindow.

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class SimpleApplet extends JApplet {
  public void init( ) {
    JPanel p = new JPanel( );
    p.setLayout(new GridLayout(2, 2, 2, 2));
    p.add(new JLabel("Username"));
    p.add(new JTextField( ));
    p.add(new JLabel("Password"));
    p.add(new JPasswordField( ));
    Container content = getContentPane( );
    content.setLayout(new GridBagLayout( )); // Used to center the panel
    content.add(p);
  }
}