import java.awt.Graphics; public class MyCanvas extends Canvas { public void paint(Graphics g) { int[] xPoints = {50, 100, 150}; int[] yPoints = {100, 50, 100}; int nPoints = 3; g.drawPolygon(xPoints, yPoints, nPoints); } }This example creates a canvas object on which we draw a triangle using the drawPolygon method. The x-coordinates and y-coordinates arrays specify the vertices of the triangle, and nPoints specifies the number of vertices. This method is part of the java.awt package library, which provides the foundation for building graphical user interfaces in Java.