• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 16. Graphics Fundamentals > Line and Figure Drawing

16.6. Line and Figure Drawing

There are several methods in class GC for drawing lines.

drawLine(int x1, int y1, int x2, int y2) Draws a line between the point (x1, y1) and the point (x2, y2).

drawPolyline(int[ ] xyArray) Draws lines between each of the points described by the pairs of (x, y) coordinates represented by consecutive values in the xyArray. In other words, it draws a line between the point (xyArray[0], xyArray[1]) and (xyArray[2], xyArray[3]), then draws a line between (xyArray[2], xyArray[3]) and (xyArray[4], xyArray[5]), and continues in this fashion until the end of the array is reached. If the variable xyLen held the length of the xyArray, the last line that is drawn is from (xyArray[xyLen-4], xyArray[xyLen-3]) to (xyArray[xyLen-2], xyArray[xyLen-1]). Because a single call to drawPolyline() can draw a large number of lines, it is more efficient to call this if you are drawing a connected sequence of lines, rather than making multiple calls to drawLine() with each segment. The result of calling this method with an array containing an odd number of ints is undefined.

drawPolygon(int[ ] xyArray) Behaves the same as drawPolyline(), except that after all the other lines are drawn, it draws a line between the last point in the xyArray and the first point in the xyArray. If, as above, the variable xyLen held the length of the array, the last line is drawn from (xyArray[xyLen-2], xyArray[xyLen-1]) to (xyArray[0], xyArray[1]).


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint