import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class uc extends Applet
implements ActionListener, MouseListener {
int x[]=new int[3], y[]=new int[3], turn = 0;
boolean reset;
public void init () {
addMouseListener (this);
}
public void paint (Graphics g) {
if (reset) {
g.setColor (Color.white);
g.fillRect (0,0,getSize().width,getSize().height);
reset = false;
g.setColor (Color.black);
}
else {
if (turn>0)
g.drawOval (x[turn-1], y[turn-1],1,1);
if (turn==3) {
triangle (g,x[0],y[0],x[1],y[1],x[2],y[2]);
turn = 0;
}
}
}
public void triangle (Graphics g, int x1, int y1,
int x2, int y2, int x3, int y3) {
g.drawLine (x1, y1, x2, y2);
g.drawLine (x2, y2, x3, y3);
g.drawLine (x3, y3, x1, y1);
}
public void mouseClicked (MouseEvent evt) {
x[turn] = evt.getX();
y[turn] = evt.getY();
turn++;
update(getGraphics());
}
public void mousePressed (MouseEvent evt) {}
public void mouseReleased (MouseEvent evt) {}
public void mouseEntered (MouseEvent evt) {}
public void mouseExited (MouseEvent evt) {}
public void update(Graphics g) {
paint (g);
}
public void actionPerformed (ActionEvent ae) {
turn = 0;
reset = true;
update(getGraphics());
}
}