// Path - Nick Taylor (16.10.2003) import java.awt.*; // Import Abstract Windows Toolkit import java.awt.event.*; // Import event handler import java.awt.geom.*; // Import Java 2D geometry package class Path extends Frame { public Path() { // Make sure we can close the window with the appropriate button click addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}}); setTitle("Path"); setSize(200,200); setBackground(Color.white); } public static void main(String[] args) { Path generalPath = new Path(); generalPath.setVisible(true); } public void paint(Graphics g) { Graphics2D gg = (Graphics2D) g; GeneralPath pathShape = new GeneralPath(); // Define start point of shape pathShape.moveTo(150,100); // Put in a straight line segment pathShape.lineTo(150,150); // Put in a quadratic segment pathShape.quadTo(50,100, 50,50); // Put in a cubic spline -- method is NOT cubicTo() pathShape.curveTo(75,75, 125,50, 150,50); // Close up the shape pathShape.closePath(); // Now draw it gg.draw(pathShape); // Iterate through path to circling control and end points PathIterator segmentList = pathShape.getPathIterator(null); double[] coords = new double[6]; Shape circle; while (!segmentList.isDone()) { int segmentType = segmentList.currentSegment(coords); circle = new Ellipse2D.Double(coords[0],coords[1],5,5); gg.draw(circle); circle = new Ellipse2D.Double(coords[2],coords[3],5,5); gg.draw(circle); circle = new Ellipse2D.Double(coords[4],coords[5],5,5); gg.draw(circle); segmentList.next(); } } }