Example 23.20: The Point subclass

Example 23.20 is a point class. A point has position but not much else so all it needs to add to shape is an implementation of draw. For good measure we'll also throw in a simple constructor that takes the location of the Point. This will be quite useful in many cases, even though it's not absolutely necessary.

package elharo.vrml;

public class Point extends shape {

  public Point(double x, double y, double z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }

  public String draw() {
  
    String node1 = "Coordinate3 { point [ ";  
    String node2 = x + " " + y + " " + z;
    String node3 = "] }\n\n"; 
    String node4 = "PointSet {\n  " +
      "startIndex 0\n  numPoints 1\n}";       
  
    return node1 + node2 + node3 + node4;
    
  }

}

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home