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

public class  buttonF4 extends JFrame implements ActionListener
{ 
  JPanel inputPanel;
  JButton b1,b2,b3;
  starP d;
  int red,green,blue;
  Color c1,c2;
  
  public buttonF4(String a)
  {    super(a);	
       inputPanel=new JPanel(); 
       inputPanel.setLayout(new BorderLayout());     
       d=new starP();
       d.setFill();
       b1=new JButton("Push button to change between draw and fill");
       b1.addActionListener(this);
       b2=new JButton("Push button to change color");
       b2.addActionListener(this);
       b3=new JButton("Push button to change background color");
       b3.addActionListener(this);
       inputPanel.add(b1,BorderLayout.NORTH);
       inputPanel.add(b2,BorderLayout.CENTER);
       inputPanel.add(b3,BorderLayout.SOUTH);
       add(inputPanel,BorderLayout.NORTH); 
       add(d,BorderLayout.CENTER); 
  }
  
  public void actionPerformed( ActionEvent e)
  {
  if(e.getSource()==b1)
  {//choose draw or select mode
  if(d.fill) d.setDraw();
  else       d.setFill();
  }
  else if(e.getSource()==b2)
  {//Random shape color
  red    =(int)(255.0*Math.random());
  green  =(int)(255.0*Math.random());
  blue   =(int)(255.0*Math.random());
  d.setColor(red,green,blue);
  }
  else if(e.getSource()==b3)
  {//selected background color
  c2=JColorChooser.showDialog(null,"color of the star ",c2 );
  d.setBColor(c2);
  }
  repaint();
  }

   public static void main(String s[])
   {
        JFrame f = new buttonF4("JFrame Graphic Button example");
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        f.setSize(800,500);
        f.setVisible(true); 
   }
}
