Calls the fillOval method of java.awt.Graphics with a square bounding box centered at specified location with width/height of 2r. - Java 2D Graphics

Java examples for 2D Graphics:Oval

Description

Calls the fillOval method of java.awt.Graphics with a square bounding box centered at specified location with width/height of 2r.

Demo Code


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

public class Main {
    /** Calls the fillOval method of java.awt.Graphics
     *  with a square bounding box centered at specified
     *  location with width/height of 2r.
     */*from w  ww  . ja  va 2s  . co  m*/
     * @param g The Graphics object.
     * @param x The x-coordinate of the center of the
     *          circle.
     * @param y The y-coordinate of the center of the
     *          circle.
     * @param r The radius of the circle.
     */

    public static void fillCircle(Graphics g, int x, int y, int r) {
        g.fillOval(x - r, y - r, 2 * r, 2 * r);
    }

    /** Calls the fillOval method of java.awt.Graphics
     *  with a square bounding box centered at specified
     *  location with width/height of 2r. Draws in the
     *  color specified.
     *
     * @param g The Graphics object.
     * @param x The x-coordinate of the center of the
     *          circle.
     * @param y The y-coordinate of the center of the
     *          circle.
     * @param r The radius of the circle.
     * @param c The color in which to draw.
     */

    public static void fillCircle(Graphics g, int x, int y, int r, Color c) {
        Color origColor = g.getColor();
        g.setColor(c);
        fillCircle(g, x, y, r);
        g.setColor(origColor);
    }

    /** Calls g.fillOval(left, top, width, height)
     *  after setting the color appropriately. Resets
     *  color after drawing.
     *
     * @param g The Graphics object.
     * @param left The left side of the bounding rectangle.
     * @param top The y-coordinate of the top of the
     *            bounding rectangle.
     * @param width The width of the bounding rectangle.
     * @param height The height of the bounding rectangle.
     * @param c The color in which to draw.
     */

    public static void fillOval(Graphics g, int left, int top, int width,
            int height, Color c) {
        Color origColor = g.getColor();
        g.setColor(c);
        g.fillOval(left, top, width, height);
        g.setColor(origColor);
    }
}

Related Tutorials