Java AWT Arc2D set type to open

Description

Java AWT Arc2D set type to open


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Arc2D;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {
  Random rnd = new Random();
  @Override/* w  ww  .j a  va2 s . c o m*/
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    
    Graphics2D g2d = (Graphics2D) g;
    g2d.setBackground(Color.BLACK);
    g2d.clearRect(0, 0, getParent().getWidth(), getParent().getHeight());
    // antialising
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);


    // 3 thickness
    g2d.setStroke(new BasicStroke(3));

    // Arc with open type
    Arc2D arc = new Arc2D.Float(50, // x coordinate 
            50,                     // y coordinate
            100,                    // bounds width 
            100,                    // bounds height
            45,                     // start angle in degrees
            270,                    // degrees plus start angle
            Arc2D.OPEN              // Open type arc
    );
    g2d.draw(arc);
  }

  public static void main(String[] args) {
    // create frame for Main
    JFrame frame = new JFrame("java2s.com");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Main Main = new Main();
    frame.add(Main);
    frame.setSize(300, 210);
    frame.setVisible(true);
  }
}



PreviousNext

Related