polyline.java

来自「Java Classic Examples是我买的两本书:《JAVA经典实例》和」· Java 代码 · 共 47 行

JAVA
47
字号
import java.util.*;
public class PolyLine
{
  // Construct a polyline from an array of points
  public PolyLine(Point[] points)
  {
    // Add the  points
    for(int i = 0; i < points.length; i++)
      polyline.add(points[i]);
  }

  // Construct a polyline from an array of coordinate
  public PolyLine(double[][] coords)
  {
    // Add the points
    for(int i = 0; i < coords.length; i++)
       polyline.add(new Point(coords[i][0], coords[i][1]));
  }

  // Add a Point object to the list
  public void addPoint(Point point)
  {
    polyline.add(point);    // Add the new point
  }

  // Add a point to the list
  public void addPoint(double x, double y)
  {
    polyline.add(new Point(x, y));
  }

  // String representation of a polyline
  public String toString()
  {
    StringBuffer str = new StringBuffer("Polyline:");
    Iterator points = polyline.iterator();           // Get an iterator

    while(points.hasNext())
      str.append(" "+ (Point)points.next());         // Append the current point

    return str.toString();
  }

  private LinkedList polyline = new LinkedList();    // Stores points for polyline
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?