next up previous
Next: HTML Form Processing Up: No Title Previous: No Title

A Simple Example

import oracle.html.*;
public class simple {
  public static void main (String args[]) {
    HtmlHead hd = new HtmlHead("Simple Example");
    HtmlBody bd = new HtmlBody();
    HtmlPage hp = new HtmlPage(hd, bd);
    hp.printHeader();
    bd.addItem(new SimpleItem(
       "This is a Heading (level2)").
       setHeading(2));
    bd.addItem(new SimpleItem("Good Day!").setBold())
      .addItem(SimpleItem.LineBreak);
    bd.addItem(SimpleItem.HorizontalRule);
    for (int i = 0; i < 5; i++) {
      bd.addItem(new SimpleItem("This is Line ")
                     .setEmphasis())
        .addItem(new SimpleItem(i))
        .addItem(SimpleItem.LineBreak);
    }
    bd.addItem(SimpleItem.HorizontalRule);
    Preformat pre = new Preformat();
    pre.addItem("void main () {\n")
       .addItem("  int i;\n\n")
       .addItem("  i = 5;\n")
       .addItem("  printf(\"i = %d\\n\",i);\n")
       .addItem("}\n");
    bd.addItem(pre); 
    bd.addItem(SimpleItem.HorizontalRule);
    hp.print();
  } // end of main
} // end of class simple

The general procedure to create a dynamic HTML document is to create the following objects:

    HtmlHead hd = new HtmlHead("Document Title");
    HtmlBody bd = new HtmlBody();
    HtmlPage hp = new HtmlPage(hd, bd);
and use the addItem method to add HTML elements to the bd object. Finally, when the page is ready to be printed, the following statements can be used:
  hp.printHeader();
  hp.print()

The SimpleItem object is used to create HTML lines of text. It is a sub-class of the more general class Item. SimpleItem has three variables:

  SimpleItem.Paragraph;
  SimpleItem.LineBreak;
  SimpleItem.HorizontalRule;
which can be used to generate the paragraph, line break and horizontal rule HTML elements respectively. There are numerous constructors for the SimpleItem object, which take as input objects of most common data types, including string, int, and float. Many of the Item class methods can be applied to SimpleItem objects such as setBold(), setEmphasis() etc.



Dr. Raj Sunderraman
7/2/1998