Microsoft® ActiveX® Controls are Automation-enabled controls that support the IDispatch COM interface, which enables the control to be scripted. These controls can also be dropped into containers, such as Visual Basic.
Hosting an ActiveX control in Java is a four-step process:
This tool will emit Java source code wrappers for the IDispatch interface implemented by the ActiveX control. The emitted Java code will include Bean-like code for adding and removing listeners for the events originating from the ActiveX control. Also, the tool produces code to appropriately manage the lifetime of the ActiveX control.
The source code will contain compiler directive code, similar to that used by J/Direct, of the form:
/** @com */
This is best illustrated with an example. The following sample uses the Microsoft Calendar ActiveX control that ships with Microsoft Office. Running the tool jactivex on the Calendar control produces Java source classes, which are then compiled into the calendar classes imported below. A Java programmer would use the control with code similar to the following:
import java.awt.*; import com.ms.activex.*; import calendar.*; // Classes from JActiveX when run on Calendar control or typelib public class UseCalendar extends Frame implements ActiveXControlListener { Calendar c; public UseCalendar() { c = new Calendar(); c.addActiveXControlListener(this); add(c); } // Implementation of ActiveXControlListener interface method(s) public void controlCreated(Object o); { if (o instanceof Calendar) { c.today(); } } }
Notice that the control is manipulated like any other Bean. The constructor code creates the Bean, registers a listener (in this case, one defined by the ActiveXControlListener interface), and then adds itself to the layout. The single method of the ActiveXControlListener interface is controlCreated. When the control is created, the Microsoft VM fires an event defined by the ActiveXControlListener interface and, if the ActiveX control supports events as this example does, the corresponding listener method on the Bean is called. The code necessary to sink the event to the corresponding listener is provided automatically by the Microsoft VM.
The result is that when the Calendar control is created, and the controlCreated method is called, which displays the month corresponding to the current date.