package elharo.vrml;
import java.util.Vector;
import java.util.Enumeration;
public class world {
String version = "#VRML V1.0 ascii\n\n";
// a Vector to hold the different objects
// in the world
Vector nodes;
public world() {
nodes = new Vector();
nodes.addElement(version);
}
public void comment(String s) {
nodes.addElement("#" + s);
}
public void addShape(shape s) {
nodes.addElement(s.draw());
}
public void draw() {
for (Enumeration e = nodes.elements();
e.hasMoreElements();) {
Object o = e.nextElement();
// There are two possible classes in the
// Vector, shapes and Strings
if (o instanceof shape) {
shape sh = (shape) o;
System.out.println(sh.draw());
}
else if (o instanceof String) {
System.out.println((String) o);
}
}
}
}
In Example 23.15 a VRML world is represented as a Vector that contains shapes and Strings. When the world is drawn all of these are printed on System.out. This can be stored in a file and served off a web server.