import java.applet.Applet;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/* <APPLET CODE = "metodo2.class" WIDTH=250 HEIGHT=200></APPLET>*/

public class metodo2 extends Applet implements ActionListener
{
    Label titulo, legenda1, legenda2, legenda3;
    TextField caixa1, caixa2, caixa3;
    Button botao;
    int x, y, z;
    TextArea ta;

    class RangeClass
    {
      int[] makeRange (int lower, int upper)
      {
        int arr[ ] = new int [ (upper - lower) + 1];
        for (int i = 0; i< arr.length; i++)
        arr [i] = lower++;
        return arr;
      }
    }

  public void init()
  {
        setLayout(new FlowLayout());
        setBackground(Color.yellow);

        setForeground(Color.red);
	titulo = new Label("Construção de um vetor");	add(titulo);

        setForeground(Color.black);
	legenda1 = new Label("Forneça o primeiro número inteiro:"); add(legenda1);
	caixa1 = new TextField("2",2);	 add(caixa1);

	legenda2 = new Label("Forneça o último numero inteiro:"); add(legenda2);
	caixa2 = new TextField("12",2);	 add(caixa2);

        legenda3 = new Label("Forneça o incremento:"); add(legenda3);
	caixa3 = new TextField("1",2);	 add(caixa3);

	botao = new Button("Cálculo do vetor"); add(botao);
	botao.addActionListener(this);

	ta = new TextArea(10,30); add(ta);
  }

  public void actionPerformed (ActionEvent e)
  {
	if(e.getSource()==botao)
	{
 	    x=Integer.valueOf(caixa1.getText()).intValue();
	    y=Integer.valueOf(caixa2.getText()).intValue();
	    z=Integer.valueOf(caixa3.getText()).intValue();

            int theArray[ ];
            RangeClass theRange = new RangeClass( );
            theArray = theRange.makeRange (x, y) ;

            ta.setText("");
            ta.append("The array: [" );

            for (int i=0; i < theArray.length; i=i+z)
            ta.append(theArray[i] + " ");

            ta.append("]");
         }
    }
}

