javacodex.com
Java Examples
Java Examples
memu home questions

Arc 2D

Here is an example that demonstrates how to draw an arc using Graphics2D.

Source: (FillArc.java)

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
 
public class FillArc extends JPanel {
 
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
 
    // fill Arc2D
    g2.setPaint(Color.red);
    g2.fill(new Arc2D.Double(20, 20, 200, 100, 90, 180, Arc2D.OPEN));
  }
 
  public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("Fill Arc Example ");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBackground(Color.white);
    frame.setSize(300, 200);
 
    FillArc panel = new FillArc();
 
    frame.add(panel);
 
    frame.setVisible(true);
  }
}
 

Output:

$ java FillArc
Output


Java Docs:

Questions answered by this page:

Java example to fill Arc in Java. How to fill and arc using using Graphics2D? How do I draw an arc in Java 2D?

Related Examples:


Contact: javacodex@yahoo.com