![]() |
![]() |
Intro. to Graphics class | |
Drawing - Lines , Rectangles | |
Drawing - Circles and Ellipse | |
Drawing - Arcs | |
Drawing - Polygons | |
Drawing - Bar Charts |
Java Programs | |
Java Keywords Dictionary | |
Java Interview Questions |
Java applet has drawOval() method to draw both circle and ellipse on the applet window.
Java also has fillOval () method to draw filled oval.
g.drawOval(int x,int y,int width,int height); g.fillOval(int x,int y,int width,int height);
The Both method takes 4 arguments, first two represents the top left corners and other two represents width and height of oval.
If width and height arguments are same, then oval becomes circle.
import java.awt.*; import java.applet.*; /* <applet code="DrawOvalEx.class" width=300 height=300> </applet> */ public class DrawOvalEx extends Applet { public void paint(Graphics g) { g.drawOval(60, 60, 150, 150); g.fillOval(220, 60, 150, 150); } }
Ovals are like a rectangle with rounded corners. Oval does not have same width and height.
import java.awt.*; import java.applet.*; /* <applet code="DrawOvalEx.class" width=300 height=300> </applet> */ public class DrawOvalEx extends Applet { public void paint(Graphics g) { g.fillOval(60, 60, 80, 100); g.fillOval(150, 60, 80, 100); g.drawOval(95, 170, 100, 50); g.drawOval(5, 90, 30, 100); g.drawOval(255, 90, 30, 100); g.drawOval(120, 250, 50, 50); } }