Draw a Triangle on the Screen, Part II

This function draws a triangle on the screen, with the points selected by the user clicking three times on the screen. It uses the paint() method from the previous example. Because the paint() routine expects the points to be sorted by x coordinate, this function takes care of that.

Calling the repaint() method of the Applet class (which is actually a method of the Component class, the great-grandparent of Applet) eventually causes the paint() method to be called.

In addition to extending the java.applet.Applet class, as all applets do, the function also implements the MouseListener interface to receive mouse ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.