vrml.eai.event
Interface BrowserListener


public interface BrowserListener

Interface of listener objects that get called when the status of a browser changes. This interface defines the browserChanged(vrml.eai.event.BrowserEvent) method that receives information about X3D browser status changes. Write a class that implements that method, create an instance of your class, add it to the Browser object by calling its Browser.addBrowserListener(vrml.eai.event.BrowserListener) method, and that method will be called when the status changes. The BrowserEvent 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 status change information, remove the listener from the Browser object by calling its Browser.removeBrowserListener(vrml.eai.event.BrowserListener) method. For more information, see the browserChanged(vrml.eai.event.BrowserEvent) method.


Method Summary
 void browserChanged(BrowserEvent evt)
          Gets called whenever the status of a Browser object changes.
 

Method Detail

browserChanged

void browserChanged(BrowserEvent evt)
Gets called whenever the status of a Browser object changes. Write a class that implements this method, create an instance of your class, add it to the Browser object by calling its Browser.addBrowserListener(vrml.eai.event.BrowserListener) method, and this method will be called when the status changes. The BrowserEvent 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 status change information, remove the listener from the Browser object by calling its Browser.removeBrowserListener(vrml.eai.event.BrowserListener) method.

Warning: Something really important that you have to keep in mind about browser 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 BrowserListener 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 the browser. Whenever the listener gets called, it forwards the event to the "onBrowserChanged" method:

 class MyClass
 {
     private static void onBrowserChanged(vrml.eai.event.BrowserEvent evt)
     {
         // Get the Browser object whose status changed
         vrml.eai.Browser browser = evt.getSource();
         switch (evt.getID())
         {
         case vrml.eai.event.BrowserEvent.INITIALIZED:
             // The browser finished to load a new scene
             ...
             break;
         case vrml.eai.event.BrowserEvent.SHUTDOWN:
             // The browser is about to unload a scene
             ...
             break;
         case vrml.eai.event.BrowserEvent.URL_ERROR:
             // Download from an URL failed
             ...
             break;
         case vrml.eai.event.BrowserEvent.CONNECTION_ERROR:
             // An error occurred when communicating with the browser
             ...
             break;
         }
     }
 
     public static void main(String[] args)
     {
         ...
         vrml.eai.Browser browser = ...;
         vrml.eai.event.BrowserListener listener = new vrml.eai.event.BrowserListener()
         {
             public void browserChanged(vrml.eai.event.BrowserEvent evt)
             {
                 MyClass.onBrowserChanged(evt);
             }
         };
         browser.addBrowserListener(listener);
         ...
         browser.removeBrowserListener(listener);
         ...
     }
 }
 

Parameters:
evt - A BrowserEvent object that contains information about the event.