Draw Ellipse2D.Float : Ellipse « 2D Graphics « Java Tutorial






import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

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

public class MainClass extends JFrame {
  public MainClass() {
    getContentPane().add(new DrawingCanvas());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 500);
    setVisible(true);
  }

  public static void main(String arg[]) {
    new MainClass();
  }
}

class DrawingCanvas extends JPanel {
  DrawingCanvas() {
    setSize(300, 300);
    setBackground(Color.white);
  }

  public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;

    Graphics2D g2 = (Graphics2D) g;

    int w = getSize().width;
    int h = getSize().height;
    Ellipse2D e = new Ellipse2D.Float(w / 4.0f, h / 4.0f, w / 2.0f, h / 2.0f);
    g2.setClip(e);

    g2.setColor(Color.red);
    g2.fillRect(0, 0, w, h);

  }
}








16.16.Ellipse
16.16.1.Create an ellipse, and then draws it several times at different rotationsCreate an ellipse, and then draws it several times at different rotations
16.16.2.Draw Ellipse2D.Float
16.16.3.Create an complex shape by rotating an ellipse.
16.16.4.Compares two ellipses and returns true if they are equal or both null.