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



public class PasMan extends JFrame
{

	public static void main(String[] args)
	{
		PasMan p = new PasMan();
		p.setVisible(true);

	}
	public PasMan()
	{
		setTitle("titolo");
		setLocation(100,100);
		setSize(400,400);


		MioPanel p = new MioPanel();
		/*bottonPanel bp= new bottonPanel();*/

		getContentPane().add(p);
		/*getContentPane().add(bp,BorderLayout.NORTH);*/
	}

	class MioPanel extends JPanel
	{
		double xPos=100;
		double yPos=100;
		double w;
		double h;
		Color c;

		public MioPanel()
		{
			JButton b = new JButton("Ellisse");
			add(b);

			JButton col = new JButton("Colore");
			add(col);
			col.addActionListener(new ActionListener()
			{
			public void actionPerformed(ActionEvent e)
			{


				c=new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255));
				//c=new Color(128,128,128,(int)(Math.random()*255));
				repaint();

			}
			});

			b.addActionListener(new ActionListener()
									{
										public void actionPerformed(ActionEvent e)
										{
											xPos=(double)(Math.random()*getWidth());
											yPos=(double)(Math.random()*getHeight());
											w=(double)(Math.random()*150);
											h=(double)(Math.random()*150);
											repaint();
											System.out.println(xPos);
											System.out.println(yPos);
										}
			});

		}

		public void paintComponent(Graphics g)
		{
			super.paintComponent(g);
			Graphics2D g2=(Graphics2D)g;
			Ellipse2D e = new Ellipse2D.Double(xPos,yPos,w,h);
			setBackground(Color.WHITE);

			g2.setPaint(c);
			g2.fill(e);
			repaint();
		}
	}


}