|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface VrmlEventListener
Interface of listener objects that get called when an
event-out slot sends an event.
This interface defines the eventOutChanged(vrml.eai.event.VrmlEvent)
method that
receives information when an event-out slot changes. Write a class
that implements that method, create an instance of your class, add
it to the EventOut
object by calling its
EventOut.addVrmlEventListener(vrml.eai.event.VrmlEventListener)
method, and
that method will be called when the slot fires an event. The
VrmlEvent
object you'll receive as a parameter of the method
contains more information about the specific event. When you're no
longer interested in receiving events, remove the listener from the
EventOut
object by calling its
EventOut.removeVrmlEventListener(vrml.eai.event.VrmlEventListener)
method. For
more information, see the eventOutChanged(vrml.eai.event.VrmlEvent)
method.
Method Summary | |
---|---|
void |
eventOutChanged(VrmlEvent evt)
Gets called whenever an event-out slot fires an event. |
Method Detail |
---|
void eventOutChanged(VrmlEvent evt)
EventOut
object by calling its
EventOut.addVrmlEventListener(vrml.eai.event.VrmlEventListener)
method, and
that method will be called when the slot fires an event. The
VrmlEvent
object you'll receive as a parameter of the method
contains more information about the specific event. When you're no
longer interested in receiving events, remove the listener from the
EventOut
object by calling its
EventOut.removeVrmlEventListener(vrml.eai.event.VrmlEventListener)
method.
Warning: Something really important that you have to keep in mind about vrml event listeners is that they get called by a special thread created inside the EAI implementation, not by the main thread of your application. For this reason, you have to synchronize access to variables and calls to other methods, i.e. you have to make your code thread-safe. For more information about thread-safety, read a good book about thread programming in Java. The EAI interface itself is thread-safe, therefore you do not have to care about thread synchronization when calling EAI methods. Also keep in mind that your code inside the listener should not block - as long as the thread is inside your listener, no other listener gets called. For performance reasons, do not try to do long-winded operations in your listener, instead return as soon as possible. If you need to perform lengthy operations, create a new thread to do them.
In practice, you usually do not create a real class that implements the VrmlEventListener interface, instead you use the special Java language feature called "anonymous classes". The following example demonstrates how to add an anonymous class as a listener to an event-out slot. Whenever the listener gets called, it forwards the event to the "onVrmlEvent" method:
class MyClass { private static vrml.eai.field.EventOutSFColor diffuseColor_changed; private static void onVrmlEvent(vrml.eai.event.VrmlEvent evt) { vrml.eai.field.BaseField field = evt.getSource(); double time = evt.getTime(); Object data = evt.getData(); if (field == diffuseColor_changed) { // diffuseColor_changed event-out slot fired an event ... } } public static void main(String[] args) { ... diffuseColor_changed = ...; vrml.eai.event.VrmlEventListener listener = new vrml.eai.event.VrmlEventListener() { public void eventOutChanged(vrml.eai.event.VrmlEvent evt) { EAIDocu.onVrmlEvent(evt); } }; diffuseColor_changed.addVrmlEventListener(listener); ... diffuseColor_changed.removeVrmlEventListener(listener); ... } }
evt
- A VrmlEvent
object that contains information about
the event.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |