Emil Emil - 1 year ago 103
Java Question

Drawing Arc in Java

I need to draw a Pie Arc in Java with start angle 350 and end angle 20.The cordinate system I follow is as follows:-


The problem here is that the start angle is greater than the end angle.For the other way round I have managed to draw the arc.Any help would be great.

Answer Source

You will have a start angle and an 'extent' angle and not an end angle. So, I don't think you would be having problem drawing an arc.

import java.awt.Graphics;
import javax.swing.JFrame;

public class Test extends JFrame{
    public static void main(String[] args){
        new Test();
    public Test(){
    public void paint(Graphics g) {
        g.fillArc(100, 100, 100, 100, 70, 30);

enter image description here

Alternatively, you can use the Arc2D class as well. One more thing to note that in java, this is the default co-ordinate mechanism.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download