⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polyline.java

📁 Java2入门经典第二章源码
💻 JAVA
字号:
public class PolyLine
{
  // Construct a polyline from an array of coordinate pairs
  public PolyLine(double[][] coords)
  {
    Point[] points = new Point[coords.length];  // Array to hold points

    // Create points from the coordinates
    for(int i = 0; i < coords.length ; i++)
      points[i] = new Point(coords[i][0], coords[i][1]);

    // Create the polyline from the array of points
    polyline = new LinkedList(points); 
  }

  // Construct a polyline from an array of points
  public PolyLine(Point[] points)
  {
    polyline = new LinkedList(points);      // Create the polyline
  }
  
  // Add a Point object to the list
   public void addPoint(Point point)
   {
    polyline.addItem(point);                // Add the point to the list
   }

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

  // String representation of a polyline
  public String toString()
  {
    StringBuffer str = new StringBuffer("Polyline:");
    Point point = (Point) polyline.getFirst();  
                                            // Set the 1st point as start
    while(point != null)
    {
      str.append(" ("+ point+ ")");         // Append the current point
      point = (Point)polyline.getNext();    // Make the next point current
    }
    return str.toString();
  }

  private LinkedList polyline;              // The linked list of points
}

⌨️ 快捷键说明

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