Home Segments Top Top Previous Next

800: Mainline

Ordinarily, applet classes define no main method, inasmuch as no use is made of a main method by a web browser. Nevertheless, you may wish to define a main method for testing an applet, either in the applet itself, or as explained in Segment 751, in a testing class. In the testing class, the main method embeds a MovieApplicationTestor instance in a JFrame instance, which is perfectly legitimate, because JApplet instances are components.

import javax.swing.*;                            
public class MovieApplicationTestor extends MovieApplication { 
 public static void main (String argv []) { 
  JFrame frame = new JFrame("Applet Testor"); 
  MovieApplicationTestor applet = new MovieApplicationTestor(); 
  frame.getContentPane().add("Center", applet); 
  frame.setSize(350, 150); 
  frame.addWindowListener(new ApplicationClosingWindowListener()); 
  frame.show(); 
 } 
}