I am attempting to add mouse dragging event to a canvas which allows users to drag a shape around the canvas.

The program reads in an SVG XML file parses it then adds shapes to an array, this is passed to the paint method of my 'MyCanvas' class which extends Canvas. From this I want to draw the shapes (rectangles, ellipses, lines) to the canvas allowing them to be moved when mouseDragged events are triggered (code below).

public class MyCanvas extends Canvas implements MouseMotionListener{

private ArrayList liList;
private ArrayList reList;
private int rectX;
private int rectY;

int re;
int li;

public MyCanvas()
{

Parser p = new Parser();
liList = p.getLineArray();
reList = p.getRectArray();
addMouseMotionListener(this);


}

public void paint(Graphics g)
{

Graphics2D g2 = (Graphics2D)g;

while(re<reList.size())
{
Shape r = (Shape)reList.get(re);


g2.setStroke(new BasicStroke(4));
g2.setPaint(Color.blue);
g2.fill(r);
g2.draw(r);
re++;
}

while(li<liList.size())
{
Shape l = (Shape)liList.get(li);


g2.setStroke(new BasicStroke(4));
g2.setPaint(Color.red);
g2.fill(l);
g2.draw(l);
li++;
}


}
public void mouseDragged(MouseEvent e)
{
int rx = e.getX();
int ry = e.getY();
repaint();

}

public void mouseMoved(MouseEvent e)
{

}

}


Can anyone help me do this? or do I need to redesign my application? If I need to redesign any ideas on the direction I should take?

Thanks