Article ID: 178994
Article Last Modified on 8/25/2005
import java.awt.*;
import java.applet.*;
public class MyApplet extends Applet
{
// fire is the private member that determines if the event fired
private boolean fire = false;
public MyApplet()
{
// Set the background to black so it can be seen
setBackground(Color.black);
}
public boolean handleEvent(Event e)
{
if(e.id == e.MOUSE_DOWN)
{
// When the user clicks, set fire to True.
fire = true;
}
return false;
}
// Scripting will call this method to see if the event occurred.
public boolean clicked()
{
// If fire is True, then 'reset' it to False and return True
if(fire)
{
fire = false;
return true;
}
// Otherwise, return False
return false;
}
}
Then, you need to create HTML:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub window_onLoad()
' Set the initial timeout for polling
window.setTimeout "checkClicked", 1000
end sub
' This is the method that the timeout calls
Sub checkClicked()
if document.app.clicked then
' The applets clicked method returned True
msgbox "You clicked my applet!"
' Reset the timeout
window.setTimeout "checkClicked", 1000
else
' The applets clicked method returned False
' Reset the timeout
window.setTimeout "checkClicked", 1000
end if
end sub
-->
</SCRIPT>
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<APPLET CODE=MyApplet.class ID=app WIDTH=320 HEIGHT=200>
</APPLET>
</BODY>
</HTML>
When the Web page is loaded, the window_onLoad function executea. It
sets a "timeout" to execute the checkClicked VBScript function. The
checkClicked function "polls" the Applet by calling the clicked method on
the Applet. If the clicked method returns True, then the checkClicked
displays a message box and resets the timeout. If the clicked method
returned False, then the checkClicked function just resets the timeout.
172202 INFO: Implementing Java Automation Objects Using AutoIDispatch
Additional query words: fire events applet script
Keywords: kbhowto kbfaq KB178994