Quick Start

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:

  1. Derive your own class from the DhModule class.

  2. Override the DhModule.documentLoad() method, and implement steps 3, 4, 5, and 6 in that method.

  3. Obtain a reference to the current document by calling getDocument().

  4. Create some elements (such as DhButton) or use findElement to access existing elements in the document.

  5. Hook an event handler into one of your elements.

  6. Add the elements to the document using the DhDocument.add() method.

  7. Write the event handler method you hooked up in step 5.

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.