Index of /guides/vrml/examples/eai/add-remove

[ICO]NameLast modifiedSizeDescription

[DIR]Parent Directory  -  
[   ]AddRemove.class16-May-2000 17:09 1.9K 
[TXT]AddRemove.java16-May-2000 17:13 2.1K 
[TXT]README.html26-Jan-1998 17:26 2.1K 
[TXT]add-remove1.html05-Feb-1998 22:21 822  
[   ]root.wrl22-Jan-1998 09:28 79  

AddRemoveTest Example (26-Jan-1998)

AddRemoveTest Example

This example is a simplified version of the AddRemoveTest example found in the EAI Spec A local modified copy of the original is in theAddRemoveTest directory.

This README file is NOT a tutorial, we just outline a few interesting bits of code: Getting a handle on a DEFed object in the scene. In this cas a Group (could be Transform) Node called ROOT (see the file root.wrl)

  // Get root node of the scene, and its EventIns
  root = browser.getNode("ROOT");
Once we got the handle we can get a handle to the field EventIn "addchildren" and to the field EventOut "removechildren"
   addChildren = (EventInMFNode) root.getEventIn("addChildren");
   removeChildren = (EventInMFNode) root.getEventIn("removeChildren");
This inserts 2 Java buttons into the applet:
    add(addButton = new Button("Add Sphere"));
    add(removeButton = new Button("Remove Sphere"));
The Java method below will catch user events (e.g. user clickin on the Add Sphere Button) and then call the xxx.setValue methods. xxx is a handle for the Event fields (see above) and .setValue will set a value (in this case pass a node reference to be added or removed).
  public boolean action(Event event, Object what) {
    // Catch all Events from type Button
    if (event.target instanceof Button) {
      Button b = (Button) event.target;
      // either addButton or removeButton has been clicked on
      if (b == addButton) {
        addChildren.setValue(shape);
      }
      else if (b == removeButton) {
        removeChildren.setValue(shape);
      }
    }
    return true;
  }


D.K.S.