DrawOval The method can be used to draw ellipses or circles of drawRect manner analogous to the method, ie by defining the location of the vertex upper left (x, y) of the rectangle which fits the definition of ellipse and its width width and height height, as indicated:
In the Following example AppletDrawOval shows how to Draw Oval or Fill Oval and set foreground color of an Applet window using drawOval , fillOval, method of Graphics class.
The Syntax for drawOval(int xTopLeft, int yTopLeft, int width, int height); and The Syntax for fillOval(int xTopLeft, int yTopLeft, int width, int height);
Following example demonstrates how to set color’s with RGB values, for this you can use a Color object. For AppletDrawOval example, an RGB(R for Red, G for Green and B
for Blue) value for dark red Color is 235 red, 50 is green, and 50 is blue. Following example AppletDrawOval shows of an applet that displays dark red Oval .
Here is the java code for the program AppletDrawOval :.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class AppletDrawOval extends Applet {
public static void main(String[] args) {
Frame OvalApplet = new Frame("Draw Oval in Applet Window Example");
OvalApplet.setSize(350, 250);
Applet AppletDrawOval = new AppletDrawOval();
OvalApplet.add(AppletDrawOval);
OvalApplet.setVisible(true);
OvalApplet.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void paint(Graphics g) {
g.setColor(Color.darkGray);
g.setFont(new Font("Arial",Font.BOLD,14));
g.drawString("Draw Oval in Applet Window Example", 50, 40);
g.setFont(new Font("Arial",Font.BOLD,10));
g.drawString("http://ecomputernotes.com", 200, 205);
//set color to darkRed
Color darkRed = new Color(235, 50, 50);
g.setColor(darkRed);
//this will draw a oval of width 50 & height 100 at (80,50)
//The Syntax for drawOval(int xTopLeft, int yTopLeft, int width, int height);
g.drawOval(80,50,50,100);
//draw filled oval
//this will draw a oval of width 50 & height 100 at (180,50)
//The Syntax for fillOval(int xTopLeft, int yTopLeft, int width, int height);
g.fillOval(180,50,50,100);
}
}