import java.applet.Applet;
import java.awt.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** Illustrates use of the showPage method of ShowHTML.
 *  Generates HTML on-the-fly and sends it to the
 *  browser via the "javascript:" URL. Using JSObject
 *  is much more flexible, but this approach doesn't
 *  require any special Java classes.
 *  <B>Only works in Netscape 3.0 and later.</B>
 */

public class TestHTML extends Applet {
  private LabeledTextField sampleLine, frameName;

  public void init() {
    setBackground(Color.white);
    sampleLine =
      new LabeledTextField("Sample HTML:", 80);
    frameName =
      new LabeledTextField("Frame Name:", 15);
    add(sampleLine);
    add(frameName);
    add(new Button("Generate HTML"));
  }

  public boolean action(Event e, Object o) {
    String text = sampleLine.getTextField().getText();
    String frame = frameName.getTextField().getText();
    String html = "<HEAD>" +
                  "<TITLE>Generated HTML</TITLE>" +
                  "</HEAD>" +
                  "<BODY BGCOLOR=WHITE>" +
                  "<H1>Generated HTML</H1>" +
                  "<H2>Your input:</H2>" +
                  "<XMP>" + text + "</XMP>" +
                  "<H2>Result:</H2>" +
                  text +
                  "</BODY>";
    if (frame.length() == 0)
      ShowHTML.showPage(this, html);
    else
      ShowHTML.showPage(this, html, frame);
    return(true);
  }
}

