Java AWT Graphics draw arc

Description

Java AWT Graphics draw arc



import java.awt.Color;
import java.awt.Graphics;

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

public class Main extends JPanel {
  @Override//from w  w  w .  ja va  2 s . c o m
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // start at 0 and sweep 360 degrees
    g.setColor(Color.RED);
    g.setColor(Color.BLACK);
    g.drawArc(15, 35, 80, 80, 0, 360);

    // start at 0 and sweep -270 degrees
    g.setColor(Color.RED);
    g.setColor(Color.BLACK);
    g.drawArc(15, 55, 80, 80, 0, -270);

    // start at 0 and sweep 360 degrees
    g.fillArc(15, 120, 80, 40, 0, 360);
  }

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

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



PreviousNext

Related