import java.io.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.geom.*;


public class  starP extends JPanel implements MouseListener,MouseMotionListener
{
  int x1,y1,x2,y2;
  int starRadius;
  Color c;
  int side;
  boolean first;
  GeneralPath x;
  
 public starP(Color c1,int n)
 {super();
  side=n;
  c=c1;
  x1=100;y1=100;x2=x1;y2=y1+30;
  first=true;
  addMouseListener(this);
  addMouseMotionListener(this);
 }
 
 public void setColor(Color c1)
 {c=c1;}
 
 public void setside(int n)
 {side=n;}
 
 public void setCizgi(int x1i,int y1i,int x2i,int y2i)
 {x1=x1i;y1=y1i;x2=x2i;y2=y2i;}
 
 public GeneralPath star(int x,int y, int n,int starRadius,double aci)
 {// bu yıldız cizime teta=pi/2+aci radyandan baslar
   GeneralPath star1=new GeneralPath();
   double teta=2.0*Math.PI/n;
   double R=starRadius;
   double r=starRadius*0.25;
   polar P1=new polar();
   polar P2=new polar();
   polar P3=new polar();
   for(int i=0;i<n;i++)
   {
     double teta1=teta*i+Math.PI/2.0+aci;
     double teta2=teta/2+teta1;
     P1.inputPolar(R,teta1);
     P2.inputPolar(r,teta2);
     if(i==0) star1.moveTo((x+(int)P1.xi()),(y-(int)P1.xj()));
     else     star1.lineTo((x+(int)P1.xi()),(y-(int)P1.xj()));
     star1.lineTo((x+(int)P2.xi()),(y-(int)P2.xj()));          
     double teta3=teta*(i+1)+Math.PI/2.0+aci;
     P3.inputPolar(R,teta3);
     star1.lineTo((x+(int)P3.xi()),(y-(int)P3.xj()));         
   }
   star1.closePath();
   return star1; 
  }
  
 public void paintComponent(Graphics g)
 {
 super.paintComponent(g);
 Graphics2D g2=(Graphics2D)g;	 
 g2.setFont(new Font("Serif",Font.BOLD,24));	 
 g2.setColor(c);
 g2.setStroke(new BasicStroke(2.0f));
 starRadius=(int)Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
 x=star(x1,y1,side,starRadius,0);
 g2.fill(x);	 
 }
    
//MouseListener (fare dinleyicisi)
public void mouseClicked(MouseEvent e)
 {}

 public void mousePressed(MouseEvent e)
 {
   x1=e.getX();y1=e.getY();}

  public void mouseReleased(MouseEvent e)
 { x2=e.getX();y2=e.getY();repaint();}

 public void mouseEntered(MouseEvent e)
 { }

 public void mouseExited(MouseEvent e)
 { }
 
//MouseMotionListener methods

 public void mouseDragged(MouseEvent e)
 {}
 public void mouseMoved(MouseEvent e)
 {}
 
}
