Microsoft SDK for Java

Creating a DHTML Document

This section covers the basic steps for creating a simple DHTML document and adding your own dynamic behavior to it by using the com.ms.wfc.html package to implement Java and DHTML. Although this section doesn't cover all the details, it introduces the remainder of this topic and the samples. The following five basic steps are required for using the com.ms.wfc.html package.

  1. Create a class called Class1 that extends DhDocument. This class represents the dynamic HTML document. Add initialization code to its initForm method to control the document’s contents and behavior.

    (Extend the behavior of your document by going to step 2.)

  2. Create new elements (such as DhButton) or create element objects that represent existing elements in the document (on the HTML page).

  3. Hook event handlers into some of your elements.

  4. In your Class1.initForm method, add the new elements using the setNewElements method, and bind any existing elements using the setBoundElements method.

  5. Write the event handler methods you hooked up in step 3.

Your document class will look something like the following example.

Example

import com.ms.wfc.html.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;

public class Class1 extends DhDocument
{
   public Class1()
   {
       initForm();
   }


   // Step 2: Create objects to represent a new elements
   // as well as elements that already exist in the HTML page.
   DhButton newElem = new DhButton();
   DhText existElem = new DhText();
        
   private void initForm( )
   {
      // Set properties to existing elements and newly added elements.
      newElem.setText("hello world");
      existElem.setBackColor(Color.BLUE);

      // Step 3: Hook up an event handler to your object.
      newElem.addOnClick(new EventHandler(this.onClickButton));


      // Step 4: Call setNewElements with an array of new elements.
      setNewElements(new DhElement[] { newElem });

      // Step 4: Call setBoundElements with an array of 
      //existing elements.
      setBoundElements(new DhElement[]{ existElem.setBindID("Sample") });
   }
        
   // Step 5: Implement your event handler.
   private void onClickButton(Object sender, Event e) {
           existElem.setText("Hello, world");
   }
}

The Java portion of the exercise is complete. The other part is the HTML code. The following example shows an HTML document containing two elements that connect this HTML to your code:

Example

<HTML>
<BODY>
<OBJECT classid="java:com.ms.wfc.html.DhModule" 
        height=0 width=0 ... VIEWASTEXT>
<PARAM NAME=CABBASE VALUE=MyProject>
<PARAM NAME=__CODECLASS VALUE=Class1>
</OBJECT>

<span id=Sample></span>
<!-- Insert your own HTML code here.-->

</BODY>
</HTML>

Open Internet Explorer 4.0, point it at your HTML file, and your application will run.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.