draw Circle - Java 2D Graphics

Java examples for 2D Graphics:Arc

Description

draw Circle

Demo Code


//package com.java2s;
import java.awt.*;

import java.awt.geom.*;

public class Main {
    public static Shape drawCircle(AffineTransform affine, double radius,
            Point2D.Double centerPt, Graphics g) {
        return drawCircle(affine, radius, Color.black, centerPt, g);
    }//from  w w  w .j a va 2 s  .com

    public static Shape drawCircle(AffineTransform affine, double radius,
            Color color, Point2D.Double centerPt, Graphics g) {
        Graphics2D g2d = null;
        if (affine == null) {
            affine = new AffineTransform();
            affine.setToIdentity();
        }
        boolean drawPath = true;
        Color origColor = null;
        if (g == null)
            drawPath = false;
        else {
            origColor = g.getColor();
            g2d = (Graphics2D) g;
        }
        Shape theCircle = new Ellipse2D.Double(centerPt.x - radius,
                centerPt.y - radius, 2.0 * radius, 2.0 * radius);
        if (drawPath) {
            g.setColor(color);
            g2d.draw(theCircle);
            g.setColor(origColor);
        }
        return theCircle;
    }
}

Related Tutorials