Microsoft SDK for Java

Firing Events from a Java Applet

Applets in Microsoft® Internet Explorer 4.0 can fire events to scripts. To do so, use the <applet> tag and specify a <param name=FireScriptEvents value=True> tag, as shown in the following example:

A look at an example taken from the AFCBean sample in the Microsoft SDK for AFC may help to demonstrate how this works.

The AFCBean class in AFCBean.java contains a handleEvent method that fires an event called itemSelected.

    /**
     *  When a item is selected, an action is performed. The LIST_SELECT
     *  event is parsed and an event called itemSelected is fired.
     */
     public boolean handleEvent(Event e)
     {
        if ((e.target instanceof UIList) && (e.id == Event.LIST_SELECT))
        {
            AFCBeanListener listener[];
            synchronized (m_listeners)
            {
                listener = new AFCBeanListener[m_listeners.size()];
                m_listeners.copyInto(listener);
            }
            for (int i=0; i<listener.length; i++)
                listener[i].itemSelected(getSelectedItem());
        }
        return super.handleEvent(e);
    }

In the AFCBean.html file, the following <applet> tag declares that the applet can fire events that will be handled by the script:

    <applet code="AFCBean.class" name="AFCBean" width="300" height="300">
        <param name="FiresScriptEvents" value="true">
    </applet>

The following JavaScript then sinks the event:

<script language="JavaScript" for="AFCBean" event="itemSelected(s)">
    txtSelectedText.value = s;
</script>

Finally, the selected string is displayed in the table on the HTML page:

    <tr>
        <td>Sinks the event itemSelected and displays the string.</td>
        <td><input name="txtSelectedText"></td>
 </tr>
</e>

When the <object> tag is supported by the Microsoft VM, it will assume the JDK 1.1 event model, so the FireScriptEvents parameter will not be required when using this tag.

For more information about VBScript, see the VBScript Web site at http://msdn.microsoft.com/scripting/ This link takes you to a site on microsoft.com.

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