[prev in list] [next in list] [prev in thread] [next in thread]
List: ms-java-com
Subject: Java COM development
From: Jonathan Coogan <n9417018 () CC ! WWU ! EDU>
Date: 1998-11-26 5:08:52
[Download RAW message or body]
I have two questions about developing a COM/ActiveX object in Java. I have written \
an ODL file that I wish to use. I am using VJ++ 1.1 and version 2.01 of the SDK.
My first question is this: After using MIDL or MKTYPLIB to create my type library, I \
use JAVATLB to generate the interfaces that my Java program needs to implement. For \
"[propput]" properties, the resultant interface contains names that begin with "put" \
(such as "putName"). When I load the final control up in VB I can get property \
values, but I cannot set them. I get a dialog box saying, "Object does not support \
this method or property." The weird thing is that when I define the same property \
with a name that begins with "set" it works ("setName"). Is this some bug in the \
JAVATLB utility? Should the generated Java interfaces really contain property names \
that begin with "set" and "get" instead of "put" and "get"?
Now for my second question: I am not getting events from my Java control in VB. I \
have noticed in the SDK samples that when you allow JAVAREG to create a type library \
for you, the event wiring is somehow handled magically, and events work perfectly in \
VB. I am using JAVAREG in the following manner:
javareg.exe /register /control /codebase:**** /class:**** /clsid:{****} \
/typelib:****.tlb /nomktyplib
I suspect that my problems are due to the fact that I am using a preexisting type \
library instead of letting JAVAREG create one for me. It is very important for me to \
do so because of the nature of my ODL file. I cannot achieve the same behavior when \
I use the automatically generated type library. Anyway, I'm hoping that someone can \
tell me how to "add VB as a listener" to my Java control. I will include a simple \
example of what I have been trying to do.
/*
* BEGIN SAMPLE ODL (SampleBean.odl)
*/
[
uuid(11372020-815E-11D2-9069-00A024D7933E),
version(1.0),
helpstring("SampleBean")
]
library SampleBean
{
importlib("StdOle2.tlb");
[
uuid(11372022-815E-11D2-9069-00A024D7933E),
dual
]
interface ISampleBean : IDispatch
{
[id(1), propget]
HRESULT textToDraw([out,retval] BSTR *textToDraw);
[id(1), propput]
HRESULT textToDraw([in] BSTR textToDraw);
};
[
uuid(11372023-815E-11D2-9069-00A024D7933E)
]
dispinterface ISampleBeanEvents {
properties:
methods:
[id(2)]
void somethingHappened();
};
[
uuid(11372024-815E-11D2-9069-00A024D7933E)
]
coclass SampleBean {
[default] interface ISampleBean;
[default, source] dispinterface ISampleBeanEvents;
};
};
/*
* END SAMPLE ODL (SampleBean.odl)
*/
At this point I use MKTYPLIB to create the SampleBean.tlb file. There are no errors. \
I then use the JAVATLB utility to generate the interfaces that I must implement. I \
allow the interfaces to be created in c:\windows\java\trustlib. The resultant \
summary file tells me that the interfaces have the following format:
public class samplebean/SampleBean extends java.lang.Object
{
}
public interface samplebean/ISampleBeanEvents extends com.ms.com.IUnknown
{
public abstract void somethingHappened();
}
public interface samplebean/ISampleBean extends com.ms.com.IUnknown
{
public abstract java.lang.String gettextToDraw();
public abstract void puttextToDraw(java.lang.String);
}
Now I build my SampleBean.java file in which I have implemented the ISampleBean \
interface. The java file looks like this:
/*
* BEGIN SAMPLE JAVA FILE (SampleBean.java)
*/
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.Date;
import com.ms.com.*;
import samplebean.*;
class SampleBean
extends Panel
implements ISampleBean
{
public SampleBean()
{
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
public void paint(Graphics g) {
g.drawString(textToDraw, 20, 20);
}
interface ISampleBeanListener
extends ISampleBeanEvents, java.util.EventListener
{
}
transient Vector listeners = new Vector();
public void addSampleBeanListener(ISampleBeanListener l) {
synchronized( listeners )
{
if(listeners == null)
listeners = new Vector();
listeners.addElement(l);
}
}
public void removeSampleBeanListener(ISampleBeanListener l)
{
synchronized( listeners )
{
listeners.removeElement(l);
}
}
protected void processMouseEvent(MouseEvent e)
{
if((e.getID()) == MouseEvent.MOUSE_PRESSED)
fire_event:
{
synchronized( listeners )
{
if(listeners == null)
break fire_event;
ISampleBeanListener snapshot[];
snapshot = new ISampleBeanListener[listeners.size()];
listeners.copyInto(snapshot);
for (int i = 0; i < snapshot.length; i++)
snapshot[i].somethingHappened();
}
}
super.processMouseEvent(e);
}
String textToDraw = "Some text...";
public String gettextToDraw() {
return textToDraw;
}
public void settextToDraw(String textToDraw)
{
// Notice this is what my first question was about.
// Weird.
puttextToDraw( textToDraw );
}
public void puttextToDraw(String textToDraw)
{
this.textToDraw = textToDraw;
repaint();
}
}
/*
* END SAMPLE JAVA FILE (SampleBean.java)
*/
Now all I have to do is register the class. I do this with the following
command:
javareg.exe /register /control /class:SampleBean /codebase:. \
/clsid:{11372024-815E-11D2-9069-00A024D7933E} /nomktyplib /typelib:SampleBean.tlb
Now when I try to work with the control in VB, the events do not work. Can someone \
please help me out? Keep in mind that it is very important to me to use the type \
library from my ODL file (even if there's no reason to in this simple example).
Thankyou.
-Jon Coogan
n9417018@cc.wwu.edu
----------------------------------------------------------------
Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe. Save time, search
the archives at http://discuss.microsoft.com/archives/index.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic