Java examples for 2D Graphics:Path
get GeneralPath First Line
//package com.java2s; import java.awt.geom.PathIterator; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; public class Main { public static Line2D getFirstLine(GeneralPath path) { double seg[] = new double[6]; double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; int index = 0; for (PathIterator i = path.getPathIterator(null); !i.isDone(); i .next()) {/*from w w w. j a va2s.c o m*/ int segType = i.currentSegment(seg); if (index == 0) { x1 = seg[0]; y1 = seg[1]; x2 = seg[0]; y2 = seg[1]; } else if (index == 1) { return (new Line2D.Double(x1, y1, seg[0], seg[1])); } index++; } return (new Line2D.Double(x1, y1, x2, y2)); } }