Create a open Arc with Arc2D.OPEN in Java

Description

The following code shows how to create a open Arc with Arc2D.OPEN.

Example


import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Arc2D;
/*  www  . java2 s.  co  m*/
import javax.swing.JComponent;
import javax.swing.JFrame;

class MyCanvas extends JComponent {
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // Draw the pie chart
    Arc2D.Float arc = new Arc2D.Float(Arc2D.OPEN);
    arc.setFrame(140, 200, 67, 46);
    arc.setAngleStart(45);
    arc.setAngleExtent(270);
    g2.setColor(Color.gray);
    g2.draw(arc);
    g2.setColor(Color.red);
    g2.fill(arc);
    g2.setColor(Color.black);
    g2.drawString("Arc2D.PIE", 140, 190);
  }
}

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

The code above generates the following result.

Create a open Arc with Arc2D.OPEN in Java




















Home »
  Java Tutorial »
    Graphics »




Animation
BufferedImage
Color
Font
Gradient
Graphics Settings
Image
Mouse Draw
Print
Shape
Text
Transform