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

[ICO]NameLast modifiedSizeDescription

[PARENTDIR]Parent Directory  -  
[   ]AddRemove.class2000-05-16 17:09 1.9K 
[TXT]AddRemove.java2000-05-16 17:13 2.1K 
[TXT]README.html1998-01-26 17:26 2.1K 
[TXT]add-remove1.html1998-02-05 22:21 822  
[   ]root.wrl1998-01-22 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.