// Simple applet illustrating use of add/removeChildren fields. import java.awt.*; import java.applet.*; import java.awt.event.*; import vrml.external.field.*; import vrml.external.Node; import vrml.external.Browser; import vrml.external.exception.*; public class AddRemoveTest extends Applet implements ActionListener { 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; // Add and Remove Buttons Button addButton; Button removeButton; public void init() { add(addButton = new Button("Add Sphere")); add(removeButton =new Button("Remove Sphere")); addButton.addActionListener(this); removeButton.addActionListener(this); output = new TextArea(5, 40); add(output); browser = Browser.getBrowser(this); 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.append("PROBLEMS!: " + e + "\n"); error = true; } catch (InvalidEventInException e) { output.append("PROBLEMS!: " + e + "\n"); error = true; } catch (InvalidVrmlException e) { output.append("PROBLEMS!: " + e + "\n"); error = true; } if (error == false) output.append("Ok...\n"); } public void actionPerformed (ActionEvent event) { Object clickedButton = event.getSource(); if (clickedButton == addButton) { addChildren.setValue(shape); } else if (clickedButton == removeButton) { removeChildren.setValue(shape); } } }