Q:

Trying to draw an arc using Java

i've been trying to draw an arc in java using this code:
g.fillArc(50, 50, 100, 100, 0, 180)

where g is a graphics object.
which yields the blue object below:

what i'm actually trying to do is produce something that looks like this:

thanks in advance for any help!

A:

Try g.fillArc(50, 50, 100, 100, 180, 180) instead.
Basically, the first angle is the where to start, the second angle is the number of degrees (from the start) it should arc through.
So if you just wanted a pie slip of 5 degrees, you would use something like g.fillArc(50, 50, 100, 100, 0, 5)
Have a look at Graphics#fillArc and Graphics2D for more info
Working example

public class PaintTest03 {

    public static void main(String[] args) {
        new PaintTest03();
    }

    public PaintTest03() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException ex) {
                } catch (InstantiationException ex) {
                } catch (IllegalAccessException ex) {
                } catch (UnsupportedLookAndFeelException ex) {
                }

                JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(new PaintPane());
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    public class PaintPane extends JPanel {

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(100, 100);
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            g.setColor(Color.RED);
            g.fillArc(0, 0, 100, 100, 180, 180);        
        }

    }

}

