import javax.swing.Timer;
import javax.swing.JFrame;
import javax.swing.JComponent;
import java.awt.*; 
import java.awt.event.*;
import java.util.*; 

class TV extends JFrame {
  TV(int actors) {
    Screen screen = new Screen(actors); 
    Timer timer = new Timer(200, screen); 
    this.add(screen); 
    this.setVisible(true); 
    this.setSize(300, 300); 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);    
    timer.start(); 
  }    
}

class Screen extends JComponent implements ActionListener, MouseMotionListener, MouseListener {
  Circle current; 
  public void mouseMoved   (MouseEvent e) { }
  public void mouseDragged (MouseEvent e) { 
    if (this.current != null) {
      this.current.moveTo(new Point(e.getX(), e.getY())); 
      this.repaint(); 
    }     
    System.out.println( "Mouse dragged at (" + e.getX() + ", " + e.getY() + ")" ); 
  }
  public void mouseEntered (MouseEvent e) { }
  public void mouseExited  (MouseEvent e) { }
  public void mousePressed (MouseEvent e) { 
    Point p = new Point(e.getX(), e.getY());
    for (Circle c : this.circles) {
      if (c.contains(p)) {
        this.current = c; 
        break;
      }
    }         
  }
  public void mouseReleased(MouseEvent e) { 
    this.current = null; 
  }
  public void mouseClicked (MouseEvent e) { }
  int number;
  ArrayList<Circle> circles; 
  Screen(int number) {
    this.number = number;     
    this.circles = new ArrayList<Circle>(); 
    for (int i = 0; i < number; i++) 
      this.circles.add( new Circle( (int) (Math.random() * 200), 
                                    (int) (Math.random() * 200), 
                                    (int) (Math.random() * 20 + 20), 
                                    new Color( (float) Math.random() , 
                                               (float) Math.random() , 
                                               (float) Math.random() ) ) );     
    this.addMouseMotionListener(this); 
    this.addMouseListener(this);
  }
  public void paintComponent(Graphics g) {
    // g.drawString("The number is: " + this.number, 50, 50); 
    for (Circle c : this.circles) {
      c.draw(g); 
    }
  }
  public void actionPerformed(ActionEvent e) {
    this.number += 1; 
    for (Circle c : this.circles) {
      c.move(); 
    }
    this.repaint(); 
  } 
}

class Program {
  public static void main(String[] args) {
    JFrame a = new TV(Integer.parseInt( args[0] )); 
  } 
}

class Circle {
  Point center; 
  int radius;
  Color color; 
  Circle(int x, int y, int radius, Color color) {
    this.center = new Point(x, y); 
    this.radius = radius;
    this.color = color; 
  }
  void draw(Graphics g) {
    g.setColor(this.color); 
    g.fillOval(this.center.x, this.center.y, this.radius * 2, this.radius * 2); 
    g.setColor(Color.BLACK); 
    g.drawOval(this.center.x, this.center.y, this.radius * 2, this.radius * 2); 
  } 
  void move() {
    if (Math.random() > 0.5) this.center.x += 1; 
    else this.center.x -= 1; 
    if (Math.random() > 0.5) this.center.y += 1; 
    else this.center.y -= 1; 
  }
  boolean contains(Point point) {
    return point.distanceTo(this.center) < this.radius;
  } 
  void moveTo(Point where) {
    this.center = where; 
  } 
}

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 ); 
  }
}