Program to design an applet which display a triangle filled with red colour and a message as "The triangle" in blue below it

A simple program which display a triangle using fillPolygon( ) method with a caption below it. Here, xPoints[ ] array holds the x coordinates and yPoints[ ] array holds the y coordinates of polygon.

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)

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

public class FilledTriangleApplet extends Applet {

 public void paint(Graphics g) {
  
  int xPoints[] = {110,180,30,110};
  int yPoints[] = {30,100,100,30};
  
  g.setColor(Color.RED);
  g.fillPolygon(xPoints, yPoints, 4);
  
  g.setColor(Color.BLUE);
  g.drawString("The triangle", 80, 140);
 }
}

/* <applet code="FilledTriangleApplet.class" width=250 height=250>
   </applet>
*/

OUTPUT

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



Comments

Popular posts from this blog

Develop an Android application to display “Hello World!” on screen

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

Build a Simple Android App to Display Student Details