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. Thanks for sharing this amazing post this is the content i really looking for, it's very helpful i hope you will continue your blogging anyway if anyone looking for AutoCAD training institute in delhi contact us +91-9311002620 visit-

  2. I am appreciative of this blog's ability to provide information on such an important subject about Aws Certification in Delhi. I discovered other segments here, and I'm excited to put these new instructions to use.

  3. You've written an excellent post, and you've shared it with us about Software Testing Training Courses Online. Your article provided me with some unique and useful knowledge. I appreciate you sharing this text with us.


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.