next up previous
Next: Application - SQL Query Up: No Title Previous: Processing form parameters

Formatting HTML Tables

In order to create a table, the following steps must be taken:

1.
Create a DynamicTable object.
2.
Create a TableRow object for each row in the table.
3.
Create either a TableDataCell object or a TableHeaderCell object for each cell in a row.
4.
Add cells to each row by using the addCell() method.
5.
Add all rows to the table by using the addRow() method.

import oracle.html.*;
public class dtable {
  public static void main (String args[]) {
    int MAXNUM = 10;

    HtmlHead hd = new HtmlHead("Dynamic Table Demo");
    HtmlBody bd = new HtmlBody();
    HtmlPage hp = new HtmlPage(hd, bd);
    hp.printHeader();

    DynamicTable tab = new DynamicTable(2);
    TableRow rows[] = new TableRow[MAXNUM];

    rows[0] = new TableRow();
    rows[0].addCell(new TableHeaderCell("I"))
           .addCell(new TableHeaderCell("I-SQUARED"));
    tab.addRow(rows[0]);       
    for (int i=1; i< MAXNUM; i++) {
      rows[i] = new TableRow();
      rows[i].addCell(new TableDataCell(""+i))
             .addCell(new TableDataCell(""+i*i));
      tab.addRow(rows[i]);
    }

    bd.addItem(tab);
    bd.addItem(SimpleItem.HorizontalRule);
    hp.print();
  } // end of main
} // end of class dtable



Dr. Raj Sunderraman
7/2/1998