Credits

Wednesday, March 17, 2010

Drawing Java Arcs

We can also create arcs from circles made. 


Use the commands below for  the arcs.


drawArc(x, y, width,height,beginning_arc_position, arc_angle_to_draw); - draws an outline of an arc;

fillArc(x, y, width,height,beginning_arc_position, arc_angle_to_draw); - draws a solid fill of an arc;


The arc starts at 0 degree at 3:00 position and moves counterclockwise. If the arc position is set to negative, then it starts from the bottom half of the circle and follows the usual direction. The arc angle shall be the angle from given point to ending point.


See the program below for given sample. 


[+/-] show/hide



import java.applet.*;
import java.awt.*;

public class GraphicsRectsCircles extends Applet { 
public void paint(Graphics g)
{
setBackground(Color.red);
g.setColor(Color.green);
g.fillArc(120, 160, 100, 100, 20, 320);
g.fillArc(200, 160, 100, 100, 340, 40);

    
}
}

AddThis