Hello All. This program lets the user select any three points within the applet window and draw a triangle. It then prints out the perimeter of the triangle and the area of the triangle. After the user has selected three points, you should then be able to click a fourth time to clear the screen and to start a new triangle. I can not figure out how to clear the applet and start the new points of the triangle. Here is my code so far:

``````import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Triangle extends Applet {

int[] xcoords = new int ;
int[] ycoords = new int ;
int pointct = 0;

public void init () {

resize (500,500);

{
public void mousePressed (MouseEvent e) {

xcoords[pointct] = e.getX();
ycoords[pointct] = e.getY();
pointct ++;
repaint();

}
}
);
}

public void paint (Graphics g) {

g.drawPolygon(xcoords, ycoords, pointct); //Draws Triangle
g.drawLine (xcoords,ycoords,xcoords,ycoords); //Draws first point

double A = Math.sqrt(Math.pow((xcoords-xcoords),2)+Math.pow((ycoords-ycoords),2));
double B = Math.sqrt(Math.pow((xcoords-xcoords),2)+Math.pow((ycoords-ycoords),2));
double C = Math.sqrt(Math.pow((xcoords-xcoords),2)+Math.pow((ycoords-ycoords),2));

double perimeter = (A+B+C);
double S = (perimeter * 0.5);
double Area = (Math.sqrt(S*(S-A)*(S-B)*(S-C)));

g.drawString ("Perimeter =" + perimeter,0,400);
g.drawString ("Area =" + Area,0,425);

}

}``````

Thank you for reading :) Any help or information would be greatly appreciated.

overwrite the canvas with a solid colour.