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.
(Extend the behavior of your document by going to step 2.)
Your document class will look something like the following 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:
<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.