Java Graphics How to - Fill Arc








Question

We would like to know how to fill Arc.

Answer

import java.awt.Color;
import java.awt.Graphics;
//  www .j a  v a 2s.c o m
import javax.swing.JComponent;
import javax.swing.JFrame;

class MyCanvas extends JComponent {

  public void paint(Graphics g) {
    g.setColor(Color.RED);
    g.fillArc(20, 20, 200, 200,200,200);
  }
}

public class FillArc {
  public static void main(String[] a) {
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setBounds(30, 30, 300, 300);
    window.getContentPane().add(new MyCanvas());
    window.setVisible(true);
  }
}