/*
 * Circles.java
 *
 * Created on April 6, 2007, 12:37 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;

public class Circles extends JFrame {
   CirclesPanel circlesPanel = new CirclesPanel();

   public Circles() {
      JButton button = new JButton("Click me");

       button.addActionListener( new ActionListener() {
           public void actionPerformed(ActionEvent e) {
               circlesPanel.addCircle();
               repaint();
           }

      }
      );
      getContentPane().add(button, BorderLayout.SOUTH);
      getContentPane().add(circlesPanel, BorderLayout.CENTER);
      setSize(400, 400);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
   }



  public static void main(String[] args) {
      new Circles();

  }
}

class CirclesPanel extends JPanel {
   ArrayList<Circle> circles = new ArrayList<Circle>();

   public void addCircle() {
       circles.add(new Circle());
   }
   public void paintComponent (Graphics page) {
       super.paintComponent(page);
       for (Circle c : circles) {
           page.drawOval(c.x, c.y, c.radius, c.radius );
       }
  }
}


class Circle {
   int x, y;
   int radius;
   static Random random = new Random();

   public Circle() {
       x = random.nextInt(400);
       y = random.nextInt(400);
       radius = random.nextInt(20) + 3;
   }
} 
