Create an complex shape by rotating an ellipse. : Ellipse « 2D Graphics « Java Tutorial






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

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

public class RotateTransformed extends JPanel {

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

    Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);

    for (double i = 0; i < 360; i += 5) {
      AffineTransform at = AffineTransform.getTranslateInstance(400 / 2, 400 / 2);
      at.rotate(Math.toRadians(i));
      g2.draw(at.createTransformedShape(e));
    }
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.add(new RotateTransformed());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);
    frame.setVisible(true);
  }
}








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.