Java Draw Ovals

Java Draw Ovals

Java Draw Ovals

Summary: In this tutorial "Java Draw Ovals", you learn drawing of drawing ovals in Java graphics.

After learning rectangles drawing, let us see the oval. Oval (Latin: Ovum meaning egg) is an elliptical shape rounded at both ends.

Supporting methods from java.awt.Graphics class

  1. void drawOval(int x, int y, int width, int height);
  2. void fillOval(int x, int y, int width, int height);

Observe the parameters of drawOval() are the same as drawRect(). Infact, the Graphics object first draws a rectangle as per the parameters and inscribes an oval, largest possible, in it. That is, the oval coordinates are that of bounded rectangle. Let us be clearer with an example.


Java Draw Ovals
Output of OvalsDrawing.java of Java Draw Ovals

g.drawOval(50, 80, 150, 100);

First a rectangle is drawn with x, y coordinates of 50 and 80 with a width and height of 150 and 100. In this rectangle, an oval is inscribed.

Java Draw Ovals

The frame you get do not close when clicked over the close icon on the title bar of the frame. It requires extra code.

Leave a Reply

Your email address will not be published. Required fields are marked *