import javax.swing.JFrame; 

public class Test extends JFrame {
  public Test() {
    this.setVisible(true); 
    this.setSize(400, 400); 
  }
  public static void main(String[] args) {
    Test a = new Test();  
    a.add( new Screen() ); 
  }
}

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

public class Screen extends JComponent implements MouseListener, MouseMotionListener {
  ArrayList<Circle> circles = new ArrayList<Circle>(); 
  public Screen() {
    for (int i = 0; i < 6; i++) {
      this.circles.add( new Circle( new Point( (int) (390 * Math.random() + 5 ) , 
                                               (int) (390 * Math.random() + 5 ) ),
                                    Color.WHITE , 
                                    (int) (Math.random() * 30 + 20 ) ) ); 
    }
    // this.alex = this.circles.get(0); 
    // System.out.println( this.alex ); 
    this.addMouseListener( this ); 
    this.addMouseMotionListener( this ); 
  }
  public void paintComponent(Graphics g) {
    for (Circle c : this.circles) 
      c.draw(g); 
  }
  Circle alex; 
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    if (this.alex == null) {
      
    } else {
      this.alex.moveTo(e.getX(), e.getY());  
      this.repaint(); 
    }
  }
  public void mouseEntered(MouseEvent e) { }
  public void mouseExited(MouseEvent e) { }
  public void mouseClicked(MouseEvent e) { }
  public void mousePressed(MouseEvent e) { 
    for (Circle c : this.circles) {
      if (c.contains(new Point(e.getX(), e.getY()))) {
        this.alex = c;
        // break;
      }
    }
    if (this.alex != null) {
      this.circles.remove(alex); 
      this.circles.add( alex );  
    }
    this.repaint(); 

  }
  public void mouseReleased(MouseEvent e) { 
    this.alex = null; 
  }
}

import java.awt.*;

public class Circle {
  Point center;
  Color color;
  int radius; 
  public Circle(Point center, Color color, int radius) {
    this.center = center;  
    this.radius = radius;
    this.color = new Color( (float) (Math.random() / 2 + 0.5) , 
                            (float) (Math.random() / 2 + 0.5) , 
                            (float) (Math.random() / 2) + 0.5f); // color; 
  }
  public void draw(Graphics g) {
    g.setColor(this.color); 
    g.fillOval(center.x - radius, center.y - radius, 2 * radius, 2 * radius); 
    g.setColor(Color.BLACK); 
    g.drawOval(center.x - radius, center.y - radius, 2 * radius, 2 * radius); 
  }
  public void moveTo(int x, int y) {
    this.center = new Point(x, y);  
  }
  public boolean contains(Point p) {
    return this.center.distanceTo(p) <= this.radius;  
  }
}

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