import java.applet.*;
import java.awt.*;

public class EingabeTest extends Applet
{   
	int n;
	
	BorderLayout myBorderLayout = new BorderLayout();
	
	Panel cp = new Panel();
    FlowLayout myFlowLayout = new FlowLayout(FlowLayout.LEFT);

	myCanvas cc = new myCanvas();

	Label myTFLabel = new Label("Berechnen bis");
	TextField myTextField = new TextField("");

	String buttonString = "OK";
	Button okButton = new Button(buttonString);
    Label myHeader = new Label("Tabelle der Quadratzahlen",Label.CENTER);

	
	public String getAppletInfo()
	{
		return "Name: RepeatTest\r\n" +
		       "Autor/Autorin: Ralph-Erich Hildebrandt\r\n" +
		       "Erstellt mit Microsoft Visual J++ Version 1.1";
	}


	public void init()
	{

		Font HeaderFont = new Font("Arial",Font.PLAIN,16);

	    resize(640, 480);
		setLayout(myBorderLayout);
		add("North",myHeader);
		myHeader.setForeground(Color.white);
		myHeader.setBackground(Color.blue);
		myHeader.setFont(HeaderFont);
		
		add("West",cp);
		cp.setLayout(myFlowLayout);
		cp.add(myTFLabel);
		cp.add(myTextField);
		cp.add(okButton);

		add("Center",cc);

	}


	public boolean action(Event evt, Object what)
	{   
		if (what.equals(buttonString))
		{

		    n = Integer.parseInt(myTextField.getText());
        	cc.repaint(n);
		    return true;
		} else
			return false;
	}


	public void paint(Graphics g)
	{
	}

	
}

class myCanvas extends Canvas
{   int n;

    public void repaint(int argn)
	{
		n = argn;
		repaint();
	}

	public void paint(Graphics g)
	{
        int i = 1;
	    int q;

		if (n != 0)
		{
			g.drawString("Die Quadratzahlen von 1 bis "+n,10,20);
		}
		while (i <= n)
		{
			q = i*i;
			g.drawString(i+"² = "+q,10,55+i*20);
			i++;
		}
	}
}	