Java Graphics Draw Arcs

Java Graphics Draw Arcs

A segment of an oval is an arc. The arc angle can be positive (sweeps anti-clockwise) or negative (sweeps clockwise). As with other figures, the arcs can be outline or solid.

Supporting methods from java.awt.Graphics class

  1. void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): draws an outline arc.
  2. void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): draws a filled (solid) arc.

where

  • x and y: Indicates the x and y coordinates where the arc is to be drawn
  • width and height: Indicates the width and height of the arc
  • startAngle: Dictates the starting angle of the arc
  • arcAngle: The angular extent of the arc (relative to the start angle)

The following program uses the above two methods.

Java Graphics Draw Arcs

An arc is drawn with starting points 60 and 70. From this point, the arc sweeps anti-clockwise direction as the angle 180 is positive. As the starting angle is 0 and ends with 180, the arc takes the shape of a semicircle. The arc width and height are 200 pixels.

The frame you get do not close when clicked over the close icon on the title bar of the frame. It requires extra code.

CHECK OUT FOR YOUR ONE STOP DESTINATION

All AWT Components – At a Glance.

Drawing All Java Geometrical Figures.

Leave a Reply

Your email address will not be published. Required fields are marked *