Java examples for 2D Graphics:Arc
Draws an arc with the specified pen width.
//package com.java2s; import java.awt.*; public class Main { /** Draws an arc with the specified pen width. Note * that the rectangle specified falls in the * <B>middle</B> of the thick line (half inside it, * half outside)./*from w w w. j ava 2 s. c o m*/ * * @param g The Graphics object. * @param left The left side of the bounding rectangle * @param top The top of the bounding rectangle * @param width The width of the bounding rectangle * @param height The height of the bounding rectangle * @param startAngle The beginning angle * <B>in degrees.</B> 0 is 3 * o'clock, increasing * counterclockwise. * @param deltaAngle The sweep angle in degrees * (going counterclockwise). * @param lineWidth The pen width (thickness of * line drawn). */ public static void drawArc(Graphics g, int left, int top, int width, int height, int startAngle, int deltaAngle, int lineWidth) { left = left - lineWidth / 2; top = top - lineWidth / 2; width = width + lineWidth; height = height + lineWidth; for (int i = 0; i < lineWidth; i++) { g.drawArc(left, top, width, height, startAngle, deltaAngle); if ((i + 1) < lineWidth) { g.drawArc(left, top, width - 1, height - 1, startAngle, deltaAngle); g.drawArc(left + 1, top, width - 1, height - 1, startAngle, deltaAngle); g.drawArc(left, top + 1, width - 1, height - 1, startAngle, deltaAngle); g.drawArc(left + 1, top + 1, width - 1, height - 1, startAngle, deltaAngle); left = left + 1; top = top + 1; width = width - 2; height = height - 2; } } } /** Draws an arc with the specified pen width * and color. * * @param g The Graphics object. * @param left The left side of the bounding rectangle * @param top The top of the bounding rectangle * @param width The width of the bounding rectangle * @param height The height of the bounding rectangle * @param startAngle The beginning angle * <B>in degrees.</B> 0 is 3 * o'clock, increasing * counterclockwise. * @param deltaAngle The sweep angle in degrees * (going counterclockwise). * @param lineWidth The pen width (thickness of * line drawn). * @param c The Color in which to draw. */ public static void drawArc(Graphics g, int left, int top, int width, int height, int startAngle, int deltaAngle, int lineWidth, Color c) { Color origColor = g.getColor(); g.setColor(c); drawArc(g, left, top, width, height, startAngle, deltaAngle, lineWidth); g.setColor(origColor); } /** Adds a Color argument to the drawArc method of * java.awt.Graphics. * * @param g The Graphics object. * @param left The left side of the bounding rectangle * @param top The top of the bounding rectangle * @param width The width of the bounding rectangle * @param height The height of the bounding rectangle * @param deltaAngle The sweep angle in degrees * (going counterclockwise). * @param lineWidth The pen width (thickness of * line drawn). * @param c The color in which to draw the arc. */ public static void drawArc(Graphics g, int left, int top, int width, int height, int startAngle, int deltaAngle, Color c) { Color origColor = g.getColor(); g.setColor(c); g.drawArc(left, top, width, height, startAngle, deltaAngle); g.setColor(origColor); } }