Introduction

The Ellipse2D class states an ellipse that is defined by a framing rectangle.

Class declaration

Following is the declaration for java.awt.geom.Ellipse2D class:

  1. public abstract class Ellipse2D
  2. extends RectangularShape

Class constructors

S.N.Constructor & Description
1 protected Ellipse2D() This is an abstract class that cannot be instantiated directly.

Class methods

S.N.Method & Description
1 boolean contains(double x, double y) Tests if the specified coordinates are inside the boundary of the Shape.
2 boolean contains(double x, double y, double w, double h) Tests if the interior of the Shape entirely contains the specified rectangular area.
3 boolean equals(Object obj) Determines whether or not the specified Object is equal to this Ellipse2D.
4 PathIterator getPathIterator(AffineTransform at) Returns an iteration object that defines the boundary of this Ellipse2D.
5 int hashCode() Returns the hashcode for this Ellipse2D.
6 boolean intersects(double x, double y, double w, double h) Tests if the interior of the Shape intersects the interior of a specified rectangular area.

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object

Ellipse2D Example

Create the following java program using any editor of your choice in say D:/ > AWT > com > tutorialspoint > gui > AWTGraphicsDemo.java

  1. package com.tutorialspoint.gui;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.awt.geom.*;
  6.  
  7. public class AWTGraphicsDemo extends Frame {
  8.  
  9. public AWTGraphicsDemo(){
  10. super("Java AWT Examples");
  11. prepareGUI();
  12. }
  13.  
  14. public static void main(String[] args){
  15. AWTGraphicsDemo awtGraphicsDemo = new AWTGraphicsDemo();
  16. awtGraphicsDemo.setVisible(true);
  17. }
  18.  
  19. private void prepareGUI(){
  20. setSize(400,400);
  21. addWindowListener(new WindowAdapter() {
  22. public void windowClosing(WindowEvent windowEvent){
  23. System.exit(0);
  24. }
  25. });
  26. }
  27.  
  28. @Override
  29. public void paint(Graphics g) {
  30. Ellipse2D shape = new Ellipse2D.Float();
  31. shape.setFrame(100, 150, 200,100);
  32. Graphics2D g2 = (Graphics2D) g;
  33. g2.draw (shape);
  34. Font font = new Font("Serif", Font.PLAIN, 24);
  35. g2.setFont(font);
  36. g.drawString("Welcome to TutorialsPoint", 50, 70);
  37. g2.drawString("Ellipse2D.Oval", 100, 120);
  38. }
  39. }

Compile the program using command prompt. Go to D:/ > AWT and type the following command.

  1. D:\AWT>javac com\tutorialspoint\gui\AWTGraphicsDemo.java

If no error comes that means compilation is successful. Run the program using following command.

  1. D:\AWT>java com.tutorialspoint.gui.AWTGraphicsDemo

Verify the following output

awt_ellipse2d.jpg