// Simple applet illustrating use of add/removeChildren fields. import java.awt.*; import java.applet.*; import vrml.external.field.*; import vrml.external.Node; import vrml.external.Browser; import vrml.external.exception.*; import netscape.javascript.JSObject; public class AddRemoveTest extends Applet { TextArea output = null; boolean error = false; // Browser we're using Browser browser; // Root of the scene graph (to which we add our nodes) Node root; // Shape group hierarchy Node[] shape; // EventIns of the root node EventInMFNode addChildren; EventInMFNode removeChildren; public void init() { add(new Button("Add Sphere")); add(new Button("Remove Sphere")); output = new TextArea(5, 40); add(output); JSObject win = JSObject.getWindow(this); JSObject doc = (JSObject) win.getMember("document"); JSObject embeds = (JSObject) doc.getMember("embeds"); browser = (Browser) embeds.getSlot(0); try { // Get root node of the scene, and its EventIns root = browser.getNode("ROOT"); addChildren = (EventInMFNode) root.getEventIn("addChildren"); removeChildren = (EventInMFNode) root.getEventIn("removeChildren"); // Instantiate our ubiquitous blue sphere hierarchy shape = browser.createVrmlFromString("Shape {\n" + " appearance Appearance {\n" + " material Material {\n" + " diffuseColor 0.2 0.2 0.8\n" + " }\n" + " }\n" + " geometry Sphere {}\n" + "}\n"); } catch (InvalidNodeException e) { output.appendText("PROBLEMS!: " + e + "\n"); error = true; } catch (InvalidEventInException e) { output.appendText("PROBLEMS!: " + e + "\n"); error = true; } catch (InvalidVrmlException e) { output.appendText("PROBLEMS!: " + e + "\n"); error = true; } if (error == false) output.appendText("Ok...\n"); } public boolean action(Event event, Object what) { if (event.target instanceof Button) { Button b = (Button) event.target; if (b.getLabel() == "Add Sphere") { addChildren.setValue(shape); } else if (b.getLabel() == "Remove Sphere") { removeChildren.setValue(shape); } } return true; } }