Java Swing Tutorial - Java Area .getPathIterator (AffineTransform at, double flatness)


Area.getPathIterator(AffineTransform at, double flatness) has the following syntax.

public PathIterator getPathIterator(AffineTransform at,    double flatness)


In the following code shows how to use Area.getPathIterator(AffineTransform at, double flatness) method.

/* w  w w  .j a  v a 2s. c  o m*/
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Ellipse2D e1 = new Ellipse2D.Double (20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double (20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area (e1);
    Area a2 = new Area (e2);

    a1.subtract (a2);

    g2.setColor (;
    g2.fill (a1);

    g2.setColor (;
    g2.drawString ("subtract", 20, 140);
    System.out.println(a1.getPathIterator(new AffineTransform(),0.5).getWindingRule());

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new Main());