This section illustrates you how to draw ellipse inside the rectangle.
To draw an Ellipse inside the rectangle, we have defined two classes Rectangle2D and Ellipse2D of package java.awt.geom.*. These classes provides a rectangle and a circle respectively.
By using draw() method of class Graphics2D, we can pass the values for the rectangle and the ellipse in the constructor of class Rectangle2D and Ellipse2D respectively to draw them.
To give the impressive and stylistic way to the outline of the specified shapes, we have used BasicStroke class. The method setStroke() sets the stroke for the Graphics2D context.
Here is the code of DrawRectangleAndEllipse.java
import java.awt.*;
|
Output will be displayed as:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Draw Ellipse in Rectangle
Post your Comment