Using Appletviewer
Sun’s JDK contains a tool called the Appletviewer that picks the <applet> tags out of the HTML file and runs the applets without displaying the surrounding HTML text. Because the Appletviewer ignores everything but APPLET tags, you can put those tags in the Java source file as comments:
// <applet code=MyApplet width=200 height=100></applet>
This way, you can run “appletviewer MyApplet.java” and you don’t need to create tiny HTML files to run tests. For example, you can add the commented HTML tags to Applet1.java:
//: c14:Applet1b.java
// Embedding the applet tag for Appletviewer.
// <applet code=Applet1b width=100 height=50></applet>
import javax.swing.*;
import java.awt.*;
public class Applet1b extends JApplet {
public void init() {
getContentPane().add(new JLabel("Applet!"));
}
} ///:~
Now you can invoke the applet with the command
appletviewer Applet1b.java
In this book, this form will be used for easy testing of applets. Shortly, you’ll see another coding approach that will allow you to execute applets from the command line without the Appletviewer.