import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    JFrame a = new JFrame(); 
    a.add( new Two(12) ); 
    a.setVisible(true); 
    a.setSize(300, 400); 
  }
}



import java.util.ArrayList;
import java.awt.Graphics;
import javax.swing.JComponent; 
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener; 
import java.awt.event.MouseListener; 

public class Two extends JComponent implements MouseMotionListener, 
                                               MouseListener 
{
  Circle current; 
  public void mouseEntered(MouseEvent e) { } 
  public void mouseExited(MouseEvent e) { } 

  public void mouseClicked(MouseEvent e) { } 
  public void mousePressed(MouseEvent e) { 

  } 
  public void mouseReleased(MouseEvent e) { 
    System.out.println("sdajfhdfdha");
    this.current = null; 
  } 

  public void mouseMoved(MouseEvent e) { } 
  public void mouseDragged(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    System.out.println( "(" + x + ", " + y + ")" ); 
    this.current.moveTo(x, y); 
    this.repaint(); 
  } 
  ArrayList<Circle> circles = new ArrayList<Circle>(); 
  public Two(int n) {
    this.addMouseMotionListener( this );
    this.addMouseListener( this ); 
    for (int i = 0; i < n; i++) {
      this.circles.add(new Circle((int) (400 * Math.random()), 
                                  (int) (400 * Math.random()), 
                                  (int) ( 30 * Math.random()) + 10, // [10, 40)
                                  new Color((float)(0.5 + 0.5 * Math.random()), 
                                            (float)(0.5 + 0.5 * Math.random()), 
                                            (float)(0.5 + 0.5 * Math.random())))); 
    }
    this.current = this.circles.get(0); 
  }
  public void paintComponent(Graphics g) {
    for (Circle c : this.circles) 
      c.draw(g); 
  } 
}


import java.awt.Color; 
import java.awt.Graphics; 

public class Circle {
  int x, y, radius;
  Color c;
  public Circle(int x, int y, int r, Color c) {
    this.x = x; 
    this.y = y;
    this.radius = r;
    this.c = c;
  } 
  public void moveTo(int x, int y) {
    this.x = x; 
    this.y = y; 
  }
  public void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillOval(this.x - this.radius, this.y - this.radius, 2 * this.radius, 2 * this.radius); 
    g.setColor(Color.BLACK); 
    g.drawOval(this.x - this.radius, this.y - this.radius, 2 * this.radius, 2 * this.radius); 
  } 
}