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

public class  buttonA2 extends JApplet implements ActionListener
{ 
  JPanel inputPanel;
  JButton b1,b2;
  starP d;
  int red,green,blue;
  Color c;
  
    public void init()
    {
       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);
       inputPanel.add(b1,BorderLayout.NORTH);
       inputPanel.add(b2,BorderLayout.SOUTH);
       inputPanel.add(d,BorderLayout.CENTER);
       add(inputPanel); 
    }
  
  public void actionPerformed( ActionEvent e)
  {
  if(e.getSource()==b1)
  {
  if(d.fill) d.setDraw();
  else       d.setFill();
  }
  else if(e.getSource()==b2)
  {
  red    =(int)(255.0*Math.random());
  green  =(int)(255.0*Math.random());
  blue   =(int)(255.0*Math.random());
  d.setColor(red,green,blue);
  }
  repaint();
  }

    public static void main(String s[])
    {
        JFrame f = new JFrame("Applet Graphic");
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        JApplet applet = new buttonA2();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.setSize(800,500);
        f.setVisible(true); 
    }  
}
