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:
PROGRAM
OUTPUT
C:\>javac FilledTriangleApplet.java
C:\>appletviewer FilledTriangleApplet.java
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
No comments:
Post a comment