Hi I have written some code that should allow the user to click on a panel and in doing so draws a circle. The user can then click that circle, selecting it (this can be showed by a change of colour), then drag that circle to a new position. However this is not working in my code. I really need some help.

Here are the classes if you want to run it and see what the problem is. I am really stuck on what is wrong. I hope you can help. Thanks in advance

package finalproject;
 
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Ellipse2D;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
 
/**
*
*/
public class PicturePanel extends JPanel implements MouseListener, MouseMotionListener {
 
public PicturePanel() {
this.setBorder(BorderFactory.createLoweredBevelBorder());
this.addMouseListener(this);
this.addMouseMotionListener(this);
setPreferredSize(new Dimension(250, 150));
setVisible(true);
 
}
 
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
for (Shape s : shapes) {
if (s == selectedShape) {
g2.setColor(Color.GREEN);
g2.fill(s);
g2.setColor(Color.BLACK);
g2.draw(s);
}
g2.setColor(Color.RED);
g2.fill(s);
g2.setColor(Color.BLACK);
g2.draw(s);
}
}
ArrayList<Point> pointsLeft = new ArrayList<Point>();
ArrayList<Point> pointsRight = new ArrayList<Point>();
public int lx, ly, rx, ry;
public Point eR1, eR2 , eL1 , eL2 ;
public Point lil;
public Point lil2;
ArrayList<Shape> shapes = new ArrayList<Shape>();
private Shape selectedShape = null;
 
public void mouseClicked(MouseEvent e) {
if (e.getSource() == RunProgram.pic1) {
 
if (selectedShape != null) {
drawSelectedLeft(eL1.x, eL1.y);
} else if (hitTest(e.getPoint()) == null) {
eL1 = e.getPoint();
//pointsLeft.add(eL1);
lx = eL1.x;
ly = eL1.y;
drawCircleLeft(eL1.x, eL1.y);
System.out.println("eL1 = " + eL1);
}
 
}
}
 
public void printPointsLeft() {
System.out.println(pointsLeft);
}
 
public void printPointsRight() {
System.out.println(pointsRight);
}
//method to determine which shape is under the cursor using the contains()
//method of each Shape against your mouse coordinates
private Shape hitTest(Point p) {
Shape hitShape = null;
for (Shape testShape : shapes) {
if (testShape.contains(p)) {
hitShape = testShape;
break;
}
}
return hitShape;
}
 
private void moveC(int x, int y) {
if (eL1.x != x || eL1.y != y) {
eL1.x = x;
eL1.y = y;
repaint(lx + (x - lx), ly + (y - ly), (2 * radius), (2 * radius));
}
}
 
public void mouseDragged(MouseEvent e) {
dragging = true;
if (selectedShape != null) {
moveC(e.getX(), e.getY());
}
}
 
public void drawCircleLeft(int x, int y) {
Shape circle = new Ellipse2D.Double(x - radius, y - radius, 2 * radius, 2 * radius);
shapes.add(circle);
repaint(x - radius, y - radius, 2 * radius, 2 * radius);
}
 
public void drawSelectedLeft(int x, int y) {
Shape circle = new Ellipse2D.Double(x - radius, y - radius, 2 * radius, 2 * radius);
selectedShape = circle;
shapes.add(selectedShape);
repaint(x - radius, y - radius, 2 * radius, 2 * radius);
}
 
public void drawCircleRight(int x, int y) {
Shape circle = new Ellipse2D.Double(x - radius, y - radius, 2 * radius, 2 * radius);
shapes.add(circle);
repaint(x - radius, y - radius, 2 * radius, 2 * radius);
}
 
public void mousePressed(MouseEvent e) {
if (e.getSource() == RunProgram.pic1) {
selectedShape = hitTest(e.getPoint());
startPoint = e.getPoint();
lx = startPoint.x;
ly = startPoint.y;
dragging = false;
}
if (e.getSource() == RunProgram.pic2) {
selectedShape = hitTest(e.getPoint());
startPoint = e.getPoint();
rx = startPoint.x;
ry = startPoint.y;
dragging = false;
}
}
 
public void mouseReleased(MouseEvent e) {
selectedShape = null;
}
 
public void mouseExited(MouseEvent e) {
}
int x, y;
int radius = 10;
private boolean dragging = false;
Point startPoint;
 
public void mouseMoved(MouseEvent e) {
}
 
public void mouseEntered(MouseEvent e) {
}
}

import java.awt.*;
import javax.swing.*;
import javax.swing.JLabel;
 
public class RunProgram extends JFrame {
 
    static JMenuBar bar;
    File fileL;
    File fileR;
    private JPanel toolPanel;
    JSlider phaseSlider;
    JButton openButton;
    int[] pixArr;
    static PicturePanel pic1, pic2;
 
    /** Creates a new instance of RunProgram */
    public RunProgram() {
        setLayout(new BorderLayout());
 
        //create panel to show original pictures
        pic1 = new PicturePanel();
        pic2 = new PicturePanel();
 
        toolPanel = new JPanel();
        toolPanel.setPreferredSize(new Dimension(100, 50));
 
        //create panel to show the phases
 
        JToolBar toolBar = new JToolBar("Still draggable");
        toolBar = new JToolBar(null, JToolBar.VERTICAL);
        toolBar.setFloatable(false);
 
        add(toolBar, BorderLayout.NORTH);
        add(pic1, BorderLayout.WEST);
        add(pic2, BorderLayout.EAST);
        add(toolBar, BorderLayout.CENTER);
 
    }
}

package finalproject;
 
public class RunApplication {
    public static void main(String[] args) {
 
        RunProgram prog = new RunProgram();
        prog.setSize(800, 500);
        prog.show();
    }
}