View RSS Feed

Java AWT

Drawing a Line

Rate this Entry
by , 03-06-2012 at 08:46 PM (482 Views)
Line2D class is used to present the line segment(x,y) in coordinate space. To specify the lines in double precision & float, use these lines.

  • Line2D.Double
  • Line2D.Float

Code below explains the drawing of a line.
Java Code:
// draw Line2D.Double
g2.draw(new Line2D.Double(x1, y1, x2, y2));
Different setline() methods are used by the Line class for explaining end points of line. End point of line will be specified by this given code. This is done by usage of constructor, for class Line2D.Float.

  • Line2D.Float(float X1, float Y1, float X2, float Y2)
  • Line2D.Float(Point2D p1, Point2D p2)

Line path stroke is defined by using the stroke object which is present in Graphics2D class.

Submit "Drawing a Line" to Facebook Submit "Drawing a Line" to Digg Submit "Drawing a Line" to Submit "Drawing a Line" to StumbleUpon Submit "Drawing a Line" to Google