Tuesday, 29 November 2016

Program to draw Ellipses on Applet

This program demonstrates the methods of Graphics class. To change the current color use the setColor( ) method which has some predefined colors like white, yellow, black, red, green, cyan, etc. For example, to change current color to "red" use the following statement:
g.setColor(Color.red);

The drawOval( ) method draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments. The syntax for drawOval( ) is given below:
void drawOval (int x, int y, int width, int height)

The fillOval( ) method fills an oval bounded by the specified rectangle with the current color. The rectangle is filled using the graphics context's current color. The syntax for fillOval( ) is given below:
void fillOval (int x, int y, int width, int height)

PROGRAM
// Draw Ellipses
import java.awt.*;
import java.applet.*;

public class DrawEllipses extends Applet 
{
 public void paint(Graphics g) 
 {
  g.drawOval(10, 10, 50, 50);
  g.setColor(Color.GREEN);
  g.fillOval(100, 10, 75, 50);
  g.setColor(Color.cyan);
  g.drawOval(190, 10, 90,30);
  g.fillOval(70, 90, 140, 100);
 }
}
/*
<applet code="DrawEllipses" width=300 height=200>
</applet>
*/

OUTPUT 

C:\>javac DrawEllipses.java 
C:\>appletviewer DrawEllipses.java



1 comment: