import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/* Generation of object of the same class. */

public class SheepDolly extends Applet
{
    // Variable beloging to our class:
    TextField info;
    Button dolly1;
    Button dolly2;
    Button dolly3;
    Button dolly4;
    Button dolly5;

    // We're going to bind this function to each sheep Dolly?.
    void dollyClicked(int number)
    {
	// Change label string.
	info.setText("Dolly " + number + "clicked.");
    }    

    // init() is called when the applet appears on the screen.
    public void init()
    {
	// Use GridLayout to enable us to place our components in a line.
	setLayout(new GridLayout(1,6));
	
	info = new TextField("No dolly clicked yet.");
	
	// Fife identical sheep dolly will be born soon.
	dolly1 = new Button();
	dolly2 = new Button();
	dolly3 = new Button();
	dolly4 = new Button();
	dolly5 = new Button();
	// We all have identical genes.

	// Now we change genes. Wow!
	dolly1.setLabel("I am Dolly1");
	dolly2.setLabel("I am Dolly2");
	dolly3.setLabel("I am Dolly3");
	dolly4.setLabel("I am Dolly4");
	dolly5.setLabel("I am Dolly5");

	// put all on the applet
	add(info);
	add(dolly1);
	add(dolly2);
	add(dolly3);
	add(dolly4);
	add(dolly5);


	// Now we change habit. Is that ethical?
	dolly1.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
		    dollyClicked(1);
		}
	    });

	dolly2.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
		    dollyClicked(2);
		}
	    });
    
	dolly3.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
		    dollyClicked(3);
		}
	    });

	dolly4.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
		    dollyClicked(4);
		}
	    });

	dolly5.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
		    dollyClicked(5);
		}
	    });
    }
}

