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

public class ipcApplet extends Applet implements Runnable
{
   int myValue;
   ipcApplet otherApplet;
   Thread myThread;
   String myName;

   public void init()
      {
      myValue = 0;
      myName = getParameter("Name");
      }
   public void start()
      {
      if (myThread == null)
         {
         myThread = new Thread(this);
         myThread.start();
         }

      }
   public void stop()
      {

      if (myThread != null)
         {
         myThread.stop();
         myThread = null;
         }

      }

   //set value in other applet and sleep for awhile
   public void run()
      {
      String otherAppletName;
      if (myName.equals("ipc1"))
         {
         otherAppletName = "ipc2";
         }
      else
         {
         otherAppletName = "ipc1";

         }
      
   
      otherApplet = (ipcApplet) getAppletContext().getApplet(otherAppletName);

   while (myThread != null)
   {
      otherApplet.ipcSetValue(myValue + 1);
      try
         {
         myThread.sleep(1000);
         }
      catch( InterruptedException e)
         {
         System.out.println("ipc interrupted!");
         }
   }

      }
   public void ipcSetValue(int value)
      {
      myValue = value;
      repaint();

      }
   public void paint(Graphics g)
      {
      g.drawString ("Value is " + myValue, 10, 10);
      }


}
