How do I draw a line in java using points?
<p>I was wondering how I'd use different points in Java to draw a line. Here is the code I have so far. I would prefer to not get the x and y of each point and just have the program use the points from x, y on its own. I am still pretty new to programming and not very good at using javadoc at this point. The following is the code I have now:</p>

<pre><code> //Create a Polygon class. A polygon is a closed shape with lines joining the corner points. 
 //You will keep the points in an array list. Use object of java.awt.Point for the point.

 //Polygon will have as an instance variable an ArrayList of Points to hold the points
 //The constructor takes no parameters but initializes the instance variable.  The
 //Polygon class also has the following methods:
 //    add: adds a Point to the polygon
 //    perimeter: returns the perimeter of the polygon
 //    draw: draws the polygon by connecting consecutive points and then
 //          connecting the last point to the first.
 //
 //No methods headers or javadoc is provided this time. You get to try your hand at writing
 //a class almost from scratch

 // Need help starting this question? In the lesson titled
 // "Starting points: Problem Set Questions", go to the
 // problem titled "Problem Set 6 - Question 3" for some tips on 
 // how to begin.

 import java.util.ArrayList; import java.awt.Point;

 public class Polygon {
     ArrayList&lt;Point&gt; points;

     /**
     **  a Polygon represents a shape with flat lines and several points.
     */ 
     public Polygon(){
     /**
     * Constructs empty array of points.
     */
     points = new ArrayList&lt;Point&gt;();
     }    /**    ** Adds points to the polygon points Array.    *@param = points x and y coordinates to add to class    */
     public void addPoints(Point point){
         points.add(point);
     }
     /**
     **gets distance between points in ArrayList
     */
     public double perimeter(){
         double perimeter = 0;
         int i = 0;
         while(i&lt;points.size()){
             if(i&lt;points.size()-1){
              perimeter = perimeter + points.get(i).distance(points.get(i+1));   
             }
             else{
              perimeter = perimeter + points.get(i).distance(points.get(0));   
             }
         }
         return perimeter;
     }
      /**    * Draws Polygon using points from points ArrayList    */
     public void drawPolygon(){
      int i = 0;
         while(i &lt; points.size()-1){
           Line2D line = Line2D.Float(points.get(i), points.get(i+1));
             line.draw();
         }
         Line2D lastLine = Line2D.Float(points.get(0), points.get(points.size()-1));
         lastLine.draw();
     } }
</code></pre>