import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Programm4HA extends Applet implements ActionListener {
  Button    Knopf1  =new Button("Zeichne");
  TextField Eingabe =new TextField("",2);
  Button    Knopf2  =new Button("Lösche alles!");

  public Programm4HA() {
    add(Knopf1);
    add(new Label("reguläres"));
    add(Eingabe);
    add(new Label("-Eck!"));
    add(Knopf2);
    Knopf1.addActionListener(this);
    Knopf2.addActionListener(this);
  }
  
  public void actionPerformed(ActionEvent Ereignis) {
    int n;
    Graphics Stift=getGraphics();
    if(Ereignis.getActionCommand() == "Zeichne") {
      try {
        n=Integer.valueOf(Eingabe.getText()).intValue();
      }
      catch(NumberFormatException Fehler) {
        n=0;
      }
      int[] x=new int[n], y=new int[n];
      for(int i=0;i<n;i++) {
        x[i]=200+(int)(100*Math.sin(2*Math.PI*i/n));
        y[i]=150+(int)(100*Math.cos(2*Math.PI*i/n));
      }
      Stift.drawPolygon(x,y,n);
    }
    else if(Ereignis.getActionCommand() == "Lösche alles!") {
      Stift.setColor(getBackground());
      Stift.fillRect(0,0,400,300);
      Stift.setColor(Color.BLACK);
    }
  }
}

