To help you get up and running using the wfc.html package to implement Java and DHTML, here is a thumbnail sketch of the steps you might perform to write a simple DHTML sample. While this is by no means the entire story, it should help set the stage before reading the rest of this topic or jumping into the samples. There are seven basic steps when creating a Java applet that uses the HTML package:
Your code should look something like this:
// Step 1: Derive from DhModule
public class MyClass extends DhModule
{
// Step 2: override the loader method
public void documentLoad(Object sender, DhEvent p)
{
// Step 3: get a document
DhDocument doc = getDocument();
// Step 4: create an element
DhButton button1 = new DhButton("Say hello");
// Step 5: wire in an event handler
button1.addOnClick( new DhEventHandler(this.onButton1Click) );
// Step 6: add it to the document
doc.add(button1);
}
// Step 7: Actually implement the event handler
public void onButton1Click( Object sender, DhEvent e )
{
DhDocument doc = getDocument();
DhText t = new DhText("Hello!");
doc.newLine();
doc.add(t);
}
}
The Java portion of the exercise is done. Now you actually write the HTML. Thanks to the advent of Java URL moniker support in Internet Explorer 4.0 (which recognizes classid=java:classname ) this step is easy. Make sure your HTML includes the following syntax (substitute ôMyClassö with the name of your class if itÆs different from the above example):
<HTML><BODY>
<OBJECT classid="java:MyClass" HEIGHT=0 WIDTH=0></OBJECT>
</HTML></BODY>
Open Internet Explorer 4.0, point it at your HTML file, and you can see your application run.