Draw Circles and Ellipses in Java Applet

In Java, Graphics class doesn’t have any method for circles or ellipses. However, the drawOval() method can be used to draw a circle or an ellipse. Ovals are just like a rectangle with overly rounded corners.
The drawOval() method takes four arguments: the first two represent the top-left corner of the imaginary rectangle and the other two represent the width and height of the oval itself.

Note: If the width and height are the same, the oval becomes a circle. The oval’s coordinates are actually the coordinates of an enclosing rectangle.


import java.awt.*;
import java.applet.*;
public class circle extend Applet
 public void paint(Graphics g)

         <applet code = "circle.class" width = "600" height = "400"></applet>

Recommended Posts:

Advanced Java
    1. Java Applet
    2. Applet Life Cycle in Java
    3. Difference Between Applet and Application
    4. Creating an Executable Applet in Java
    5. Displaying Numerical values in Applet
    6. An Applet Program to Add Two Numbers
    7. Event Handling in Applet
    8. AWT Event Classes
    9. AWT Graphics Class
    10. Draw a line and rectangle in Java Applet
    11. Draw Circles and Ellipses in Java Applet
    12. Draw a Polygon in Java Applet
    13. AWT Hierarchy | AWT Package
    14. Swing in Core Java