import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Painter
extends JPanel {
private Vector Lines =
new Vector();
/* Vector to keep track of all
the lines that are drawn */
private Vector Rectangles =
new Vector();
/* Vector to keep track of
all the rectangles that are drawn*/
private Line newL;
// Instantiate a new Line see Line.java
private Rectangle newR;
// Instantiate a new Rectangle see Rectangle.java
public Painter(){
setBackground
(Color.
WHITE);
addMouseListener(l1);
}
/* draw all the lines in the Vector */
super.paintComponent(g);
((Line) i.
next()).
draw(g
);
}
}
newL =
new Line(e.
getPoint(),e.
getPoint());
/*
start a new Line and get the point where you
pressed the mouseButton*/
}
newL.p2 = e.getPoint();/* get the point where
you released the mouse*/
Lines.add(newL);/*add the new line to the
vector so that it can keep track of it*/
repaint();/*repaint, draw all the lines again */
}
};
}