Xj3D Browser Applet Example

Anchor Status bar Showing

HTML Modifications

For this example, only one very minor change is needed in the HTML from the original tutorial. To demonstrate an anchor (or any pointing device sensor) showing it's description, we need to have a X3D file with such a node in it and will be discussed later in this tutorial. Updated your modelURL to point to this new variable.

Java Code Modifications

To get mouse over messages you will need to make use of an Xj3D-specific extension interface named Xj3DStatusListener that can be found in our usual extension package of org.xj3d.sai. Start the class definition by extending this interface.


public class Xj3DAppletTutorial5 extends Applet implements Xj3DStatusListener {

There are three methods that need to be implemented in this interface, only one of which will be useful for this tutorial (but may be useful for your other project requirements). The method of interest is named updateStatusMessage and has a single string parameter which is the message coming from the description field of the anchor. This is also the generic interfaces for all status information, so you will see many more messages coming through this interface other than just the sensor descriptions. The other two methods you can leave empty.


    public void progressUpdate(String id, String msg, float perc) {
    }

    public void updateFramesPerSecond(float fps) {
    }

    public void updateStatusMessage(String msg) {
    }

Within the updateStatusMessage method is where you do the work of pushing the description to the containing web browser. To do this, you make use of the method showStatus() method on the Applet class that we are extending. It also takes a string, but has a slight functional difference between the way Xj3D sends messages and what it needs. In Xj3D, when nothing is to be displayed as status (eg the mouse is no longer over the box) the updateStatusMessage method is called with a null for the parameter value. However, if you pass that null value to showStatus the request will be ignored. To work around this you need to pass a zero length string. The result is that the complete method looks like this:


    public void updateStatusMessage(String msg) {
        if(msg == null)
            showStatus("");
        else
            showStatus(msg);
    }

X3D Modifications

We start with the basic Anchor X3D example from the anchor tutorial and add a value for the description field.

<Scene>
  <Anchor DEF='anchor' parameter='showframe'
             url='http://www.foo.org/greenFrame.html'
			 description='This is your description to show'>
    <Shape>

etc...

Source Files


[ Xj3D Homepage | Xj3D @ Web3d | Screenshots | Dev docs | Dev Releases | Contributors | Getting Started ]
Last updated: $Date: 2008-08-29 00:03:26 $