Home Segments Top Top Previous Next

796: Mainline

Suppose that you want to transform into an applet the MovieApplication class defined in Segment 792. You need to make several changes:

First, define the class to extend the JApplet class, rather than the JFrame class.

public class MovieApplication extends JApplet {  
... 
} 

Second, remove the definition of the main method.

Third, because applets have no close button, remove the LocalWindowAdapter subclass definition and remove the call to addWindowListener. Because you remove the listener, you no longer need to import the java.awt.event package.

Fourth, transform the one-parameter constructor, which passes along a title to the constructor in the direct superclass, into a zero-parameter constructor. Eliminate the calls to the superclass constructor and to the setSize and show methods.