package elte.java2_utikalauz5.java2d; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; /** peldaprogram az iteratorok hasznalatara. @link.forrásfájl {@docRoot}/../data/java2d/src Iterator.java @link.letöltés {@docRoot}/../data/java2d Iterator.jar @since Java 2 Útikalauz programozóknak */ class Iterator extends Canvas { /** Verziószám */ private final static long serialVersionUID = 15L; public void paint (Graphics g) { Graphics2D g2 = (Graphics2D) g; QuadCurve2D gorbe = new QuadCurve2D.Float (10.0f, 200.0f, 100.0f, 0.0f, 190.0f, 200.0f); PathIterator korvonal = gorbe.getPathIterator (null); FlatteningPathIterator laposKorvonal = new FlatteningPathIterator (korvonal, 0.1); Point2D pontok[] = new Point2D [200]; int i = 0; while (!laposKorvonal.isDone ()) { float[] koordinatak = new float [6]; switch (laposKorvonal.currentSegment (koordinatak)) { case FlatteningPathIterator.SEG_MOVETO: case FlatteningPathIterator.SEG_LINETO: pontok[i] = new Point2D.Float (koordinatak[0], koordinatak[1]); } i++; laposKorvonal.next(); } for (int j = 0; j < i - 1; j++) { Line2D vonal = new Line2D.Double (pontok[j], pontok[j+1]); g2.draw (vonal); } } public static void main (String[] args) { Frame f = new Frame (); f.add (new Iterator ()); f.addWindowListener ( new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } } ); f.setSize (300, 300); f.setVisible (true); } }