
import java.awt.*;

public class displaywall extends BufferedApplet
{
   int w = 0, h = 0;
   int hw = 40, hh = 50;

   final static int nHands = 8;
   int n = -1;
   int handX[] = new int[nHands];
   int handY[] = new int[nHands];
   int handState[] = new int[nHands];

   Color touchColor = new Color(255,128,128, 32);
   Color hoverColor = new Color(255,128,128, 32);
   Color traceColor = new Color(128,  0,  0, 32);

   public void render(Graphics g) {
      if (w == 0) {
         w = bounds().width;
         h = bounds().height;
         for (int i = 0 ; i < nHands ; i++) {
            handX[i] = w/2 + (2 * i - nHands) * 30;
            handY[i] = 7 * h / 8;
         }
      }
      g.setColor(Color.black);
      g.fillRect(0, 0, w, h);


      for (int i = 0 ; i < nHands ; i++) {
         int x = handX[i] - hw/2;
         int y = handY[i] - hh/2;
         switch (handState[i]) {
         case 2:
            g.setColor(touchColor);
            for (int j = 0 ; j < 8 ; j++)
               g.fillOval(x+j, y+j, hw-j-j, hh-j-j);
            break;
         case 1:
         case 3:
            g.setColor(hoverColor);
            for (int j = 0 ; j < 16 ; j += 2)
               g.fillOval(x+j, y+j, hw-j-j, hh-j-j);
            break;
         case 0:
            g.setColor(traceColor);
            for (int j = 0 ; j < 16 ; j += 2)
               g.fillOval(x+j, y+j, hw-j-j, hh-j-j);
            break;
         }
      }

      animating = true;
   }

   public boolean keyUp(Event e, int key) {
      if (key >= '1' && key <= '8')
         handState[key - '1'] = (handState[key - '1'] + 1) % 4;
      return true;
   }

   int mx = 0, my = 0;

   public boolean mouseDown(Event e, int x, int y) {
      n = -1;
      for (int i = 0 ; i < nHands ; i++) {
         int dx = x - handX[i];
         int dy = y - handY[i];
         if (Math.abs(dx) < hw/2 && Math.abs(dy) < hh/2) {
            n = i;
            mx = x;
            my = y;
         }
      }
      return true;
   }

   public boolean mouseDrag(Event e, int x, int y) {
      if (n >= 0) {
         y = Math.max(y, h/2);
         handX[n] += x - mx;
         handY[n] += y - my;
         mx = x;
         my = y;
      }
      return true;
   }

   public boolean mouseUp(Event e, int x, int y) {
      n = -1;
      return true;
   }
}


