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