Hi, I have written some code which when a mouse is clicked, a red circle is drawn at that position. The x,y coordinates are stored in an ArrayList. What I now want to do is enable the circles to be selected and then dragged. When the mouse is released the new coordinates need to replace the old coordinates. I hope someone can help! thanks
ArrayList<Point> pointsLeft = new ArrayList<Point>();
ArrayList<Point> pointsRight = new ArrayList<Point>();
public void mouseClicked(MouseEvent e) {
if (e.getSource() == picture1) {
pointsLeft.add(e.getPoint());
drawCircleLeft(e.getX(), e.getY());
printPointsLeft();
repaint();
}
if (e.getSource() == picture2) {
pointsRight.add(e.getPoint());
drawCircleRight(e.getX(), e.getY());
printPointsRight();
repaint();
}
}
public void printPointsLeft() {
System.out.println(pointsLeft);
}
public void printPointsRight() {
System.out.println(pointsRight);
}
public void drawCircleLeft(int x, int y) {
Graphics g1 = picture1.getGraphics();
g1.setColor(Color.RED);
g1.drawOval(x - radius, y - radius, 2 * radius, 2 * radius);
g1.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
}
int x, y;
int radius = 5;
public void drawCircleRight(int x, int y) {
Graphics g2 = picture2.getGraphics();
g2.setColor(Color.RED);
g2.drawOval(x - radius, y - radius, 2 * radius, 2 * radius);
g2.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}