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



Comments

Post a Comment

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Program to input age from user and throw user-defined exception if entered age is negative

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.