A Java program communicates with an ActiveX component through a group of interfaces. I used the Java Type Library Wizard, following the procedure outlined in the section titled “Using a COM Object from Java” on page 128, to generate interfaces for the Super Label and Timer controls. The following interfaces were generated for the Timer control.
public class ietimer/IeTimer extends java.lang.Object
{
}
public interface ietimer/DIeTimerEvents
extends com.ms.com.IUnknown
{
public abstract void Timer();
}
public interface ietimer/IIeTimer
extends com.ms.com.IUnknown
{
public abstract void AboutBox();
public abstract int getInterval();
public abstract void putInterval(int);
public abstract int getEnabled();
public abstract void putEnabled(int);
}
public interface ietimer/enumBoolType
extends com.ms.com.IUnknown
{
public static final int ValFalse;
public static final int ValTrue;
}
Taking the framework applet generated by Developer Studio, I added some constants and some references for Abstract Window Toolkit (AWT) controls. The SPEED constants define the range of settings for the Timer control; the event interval will be between 0.5 and 5 seconds, and the applet will change the interval in increments of 0.1 second.
// Import Java packages
import java.applet.*;
import java.awt.*;
// Import Timer and Super Label ActiveX control packages
import ietimer.*;
import ielabel.*;
public class AXGlue extends Applet
{
//-----------------------
// Constants
//-----------------------
static final int SPEED_MIN = 500; // 0.5 second
static final int SPEED_MAX = 5000; // 5 seconds
static final int SPEED_INC = 100; // tenths of seconds
//-----------------------
// Fields
//-----------------------
// ActiveX controls
IIeLabel m_AXLabel;
IIeTimer m_AXTimer;
// AWT components
Button m_btnFaster;
Button m_btnSlower;
List m_lstOutput;
§
Two references, m_AXTimer and m_AXLabel, will refer to the web page’s ActiveX controls. I’ve also defined three controls as part of the Java applet. These controls will be referenced by the m_btnFaster, m_btnSlower, and m_lstOutput fields.
The constructor doesn’t have anything to do; the destroy, paint, start, and stop methods are also empty. All initialization takes place in the init method. I create the three AWT controls and position them in the applet window.
§
//-----------------------
// Methods
//-----------------------
public AXGlue()
{
// Nothing to do
}
public String getAppletInfo()
{
return "Name: AXGlue\r\n" +
"Author: Scott Robert Ladd\r\n" +
"Created with Microsoft Visual J++ " +
"Version 1.1";
}