Howdy. 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*; 

class One extends JFrame {
  One() {
    Two b = new Two(); 
    this.add( b ); 
    this.addMouseMotionListener( b ); 
    this.setVisible(true);
    this.setSize(400, 400);
    this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 
  }
  public static void main(String[] args) {
    JFrame a = new One(); 
  }  
}

class Two extends JComponent implements MouseMotionListener { 
  int x, y; 
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    int x = e.getX(), y = e.getY();
    this.x = x; this.y = y;  
    this.repaint(); 
    System.out.println("Mouse being dragged..."); 
  }
  public void paintComponent(Graphics g) {
    g.drawString( "(" + this.x + ", " + this.y + ")", this.x, this.y);
  }
}


Then I wrote this:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*; 
import java.util.*;

class One extends JFrame {
  One() {
    Two b = new Two(); 
    this.add( b ); 
    this.addMouseMotionListener( b ); 
    this.addMouseListener( b ); 
    this.setVisible(true);
    this.setSize(400, 400);
    this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 
  }
  public static void main(String[] args) {
    JFrame a = new One(); 
  }  
}

class Two extends JComponent implements MouseMotionListener, MouseListener { 

  public void mouseEntered(MouseEvent e) { }
  public void mouseExited(MouseEvent e) { }
  public void mouseClicked(MouseEvent e) { }

  Circle current; 

  public void mousePressed(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    Point p = new Point(x, y); 
    for (Circle c : this.circles) {
      if (c.contains(p)) {
        this.current = c;
        break; 
      }
    } 
  }
  public void mouseReleased(MouseEvent e) { 
    this.current = null; 
  }

  int x, y; 
  ArrayList<Circle> circles; 
  Two() {
    this.circles = new ArrayList<Circle>(); 
    for (int i = 0; i < 20; i++) {
      this.circles.add( new Circle( new Point((int) (Math.random() * 300 + 50), 
                                              (int) (Math.random() * 300 + 50) ), 
                                              (int) (Math.random() *  20 + 10) )); 
    }
  }
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    int x = e.getX(), y = e.getY();
    this.x = x; this.y = y;  
    if (this.current != null) 
      this.current.moveTo(new Point(x, y)); 
    this.repaint(); 
    System.out.println("Mouse being dragged..."); 
    
  }
  public void paintComponent(Graphics g) {
    g.drawString( "(" + this.x + ", " + this.y + ")", this.x, this.y);
    for (Circle c : this.circles) 
      c.draw( g ); 
  }
}

class Circle {
  Point center; 
  int radius;
  Circle(Point c, int r) {
    this.center = c; 
    this.radius = r; 
  }
  void draw(Graphics g) {
    g.setColor(Color.YELLOW); 
    g.fillOval(this.center.x, this.center.y, this.radius * 2, this.radius * 2);
    g.setColor(Color.BLUE); 
    g.drawOval(this.center.x, this.center.y, this.radius * 2, this.radius * 2);
  }
  void moveTo(Point where) {
    this.center = where; 
  }
  boolean contains(Point a) {
    return a.distanceTo(this.center) <= this.radius; 
  }
}

class Point {
  int x, y;
  Point(int x, int y) {
    this.x = x; 
    this.y = y; 
  } 
  double distanceTo(Point other) {
    int dx = this.x - other.x; 
    int dy = this.y - other.y; 
    return Math.sqrt( dx * dx + dy * dy); 
  }
}

The program works but is a bit off. 

How do we fix it? 

--