The problem is as in question.
I read the example so many times already, but I still can’t bring it to work.
The idea is to write an Event in Java and write a callback for MATLAB.
First I wrote my event class: package.EventTest.
Then I built it and in added the path with this classes to javaclasspath.
Then in matlab I execute:
evt = package.EventTest
set(evt,'TestEventCallback',@(h,e)disp(h))
evt.notifyMyTest
after line “evt.notifyMyTest” it should display something, but comes nothing.
I used a debugger and as it comes to function “notifyMyTest” I see that the vector with listeners is empty. So it can’t show anything. What do I do wrong?
Does this line “set(evt,’TestEventCallback’,@(h,e)disp(h))” have to add listener to this vector?
Or maybe there is another one possibility to challenge it?
Thanks in advance,
Lex
UPD: My Java class in package “package” (example):
public class EventTest {
private java.util.Vector data = new java.util.Vector();
public synchronized void addMyTestListener(MyTestListener lis) {
data.addElement(lis);
}
public synchronized void removeMyTestListener(MyTestListener lis) {
data.removeElement(lis);
}
public interface MyTestListener extends java.util.EventListener {
void testEvent(MyTestEvent event);
}
public class MyTestEvent extends java.util.EventObject {
private static final long serialVersionUID = 1L;
public float oldValue,newValue;
MyTestEvent(Object obj, float oldValue, float newValue) {
super(obj);
this.oldValue = oldValue;
this.newValue = newValue;
}
}
public void notifyMyTest() {
java.util.Vector dataCopy;
synchronized(this) {
dataCopy = (java.util.Vector)data.clone();
}
for (int i=0; i<dataCopy.size(); i++) {
MyTestEvent event = new MyTestEvent(this, 0, 1);
((MyTestListener)dataCopy.elementAt(i)).testEvent(event);
}
}
}
I think, I found another way to do what I want.
Now I use
PropertyChangeSupportandPropertzChangeListener.In Matlab I add
Then from Java-code I send
And my Matlab code is notified.
Looks like it’s working