Program to design an applet which draws a circle (having color BLUE) inside a triangle (having color YELLOW)

Given program will draw a circle inside a triangle. The color of circle is "blue" and triangle having color "yellow". To fill circle with respective colours first we have to set the colour using setColor(Color c) method of Graphics class and then use the fillPolygon() and fillOval( ) method.

The fillPolygon( ) method Fills a closed polygon defined by arrays of x and y coordinates. The syntax for fillPolygon( ) is given below: 

void fillPolygon (int[ ] xPoints, int[ ] yPoints, int nPoints)
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)

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class CircleInsideTriangle extends Applet {

 public void paint(Graphics g) {
  // Draws a triangle 
  int xPoints[] = {120, 220, 30};
  int yPoints[] = {30, 220, 220};
  g.fillPolygon(xPoints, yPoints, 3);
  // Draws a circle
  g.fillOval(90, 120, 70, 70);

/* <applet code="CircleInsideTriangle" width=250 height=250>




  1. Anyone looking for Best Consulting Firm for Fake Experience Certificate Providers in chennai, India with Complete Documents So Dreamsoft Consultancy is the Best Place.Further Details Here- 9599119376 or VisitWebsite-


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.

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.

Program to draw Smiley in Applet