Java Draw Circle drawCircle(Graphics g, int centerX, int centerY, int diameter)

Here you can find the source of drawCircle(Graphics g, int centerX, int centerY, int diameter)

Description

Draws a circle with the specified diameter using the given point coordinates as center.

License

Open Source License

Parameter

Parameter Description
g Graphics context
centerX X coordinate of circle center
centerY Y coordinate of circle center
diameter Circle diameter

Declaration

public static void drawCircle(Graphics g, int centerX, int centerY, int diameter) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics;
import java.awt.Point;

public class Main {
    /**//from  w  w  w .j av a  2  s . co m
     * Draws a circle with the specified diameter using the given point as center.
     * @param g Graphics context
     * @param center Circle center
     * @param diameter Circle diameter
     */
    public static void drawCircle(Graphics g, Point center, int diameter) {
        drawCircle(g, (int) center.getX(), (int) center.getY(), diameter);
    }

    /**
     * Draws a circle with the specified diameter using the given point coordinates as center.
     * @param g Graphics context
     * @param centerX X coordinate of circle center
     * @param centerY Y coordinate of circle center
     * @param diameter Circle diameter
     */
    public static void drawCircle(Graphics g, int centerX, int centerY, int diameter) {
        g.drawOval((int) (centerX - diameter / 2), (int) (centerY - diameter / 2), diameter, diameter);
    }
}

Related

  1. drawCircle(Graphics g, int x, int y, int diameter)
  2. drawCircle(Graphics2D g2d, int x, int y, int size)
  3. drawCircle(Graphics2D graphics, double x, double y, double radius)
  4. drawCircle(int x, int y, int radius, Graphics2D graphics2D)