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

/**
 * Class CircleButton 
 * 
 * @author smh
 * @version 1
 * @date 11/19/2013
 */
public class CircleButton extends JFrame
{
	
	public CircleButton(String title) {
		setTitle(title);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(500, 500);
	
		DrawingPanel drawPanel = new DrawingPanel();
		add(drawPanel, BorderLayout.CENTER);
		
		JButton button = new JButton("click for new circle");
		button.addActionListener (new ActionListener () {		
			public void actionPerformed(ActionEvent ev) {
				System.out.println("here");
				update(getGraphics());
			} } );
		add(button,BorderLayout.NORTH);
	}

    public static void main(String[] args) {
       	CircleButton gui = new CircleButton("Draw a Circle under Button Control");
       	gui.setVisible(true);
    }
}

class DrawingPanel extends JPanel {

	Color[] colors = {Color.BLACK, Color.CYAN, Color.DARK_GRAY, Color.GRAY, Color.GREEN, Color.LIGHT_GRAY,
					  Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE, Color.YELLOW};

	Color circleColor = Color.black;
	
	public void paintComponent (Graphics g) {

	  int height = getHeight();       // Component methods to get size of drawing surface
	  int width = getWidth();	        
	  int diameter = Math.min(height, width) / 10;     // ok, ok, a magic number for # of circles
	  
	  g.setColor(Color.BLUE);
	 
	  g.fillRect(0, 0, width , height);   // make background color blue
	         
	  for (int x = width-diameter, y= 0; x >=0 && y <=height-diameter; x -= diameter, y += diameter)  // u gotta prob with , ?
	      {
		  int rad = (int) (Math.random() *(diameter-2)) +5;
		  int ix = (int) (Math.random() * colors.length) ;
		  g.setColor(colors[ix]);
	      g.fillOval(x, y, rad, rad);
	      }  
	}
}


