      // General Information
      // ------------------------------------------------------------

      // File:  Piano.java
      // Type:  java applet
      // Date:  Sun Jan  5, 1997
      // Name:  blue
      // Line:  (Piano V6)


      // Applet Description
      // ------------------------------------------------------------

      /*

        The new feature is that a dot appears on a key when it is
        pressed and disappears when it is realeased.

      */

      // Package Identification
      // ------------------------------------------------------------

         package development.piano.v6;

      // Required packages
      // ------------------------------------------------------------

         import java.awt.*;
         import java.applet.*;
         import blue.painter.*;
         import blue.shapes.*;


      // Applet class
      // ------------------------------------------------------------

         public class Piano extends java.applet.Applet
         {

            private int whiteKeyHeight = 80;
            private int whiteKeyWidth = 20;
            private int nrOfWhiteKeys = 8;

            private Keyboard keyboard = null;
            private KeyboardBuffer keyboardBuffer = null;

         // overriding init of java.awt.applet
            public void init() 
            {
            // Establish a layout so that the included
            // component with be centered within the applet.
               this.setLayout(new GridLayout(1,1));

            // Add a key
               keyboard = new Keyboard(nrOfWhiteKeys,whiteKeyHeight,whiteKeyWidth);
               keyboardBuffer = new KeyboardBuffer(keyboard);
               add(keyboardBuffer);
               //gui = new VirtualPianoPanel(new Button("?"),keyboardBuffer,new Button("?"));
               //add(gui);

            }

         }


         class Key extends Painter
         {
            int width;
            int height;
            blue.shapes.Rectangle border;
            Circle dot;
            Color playColor = new Color(115,220,103);

            Key(int height, int width)
            {
               super(width,height);
               this.width = width;
               this.height = height;
               border = new blue.shapes.Rectangle(height-1,width-1);
               dot = new Circle(7);
            }

            public boolean mouseDown(Event e, int x, int y)
            {
               highlight();
               return true;
            }

            public boolean mouseUp(Event e, int x, int y)
            {
               unhighlight();
               return true;
            }

            public void draw()
            {
              draw(border);
            }
               
            public void highlight()
            {
               setPenColor(playColor);
               jbk(height/4);
               paint(dot);
               jfd(height/4);
               setPenColor(Color.black);
               repaint();
            }

            public void unhighlight()
            {
               setPenColor(Color.white);
               jbk(height/4);
               paint(dot);
               jfd(height/4);
               setPenColor(Color.black);
               repaint();
            }


         }

         class Keyboard extends SupportingPainter
         {
            int size;
            double width;
            double height;
            blue.shapes.Rectangle frame;

            Key keys[];

            Keyboard(int s, int h, int w)
            {
               super(s+20,w*s+20);
               setLayout(new GridLayout(1,s));

               frame = new blue.shapes.Rectangle(h+10,s*w+10);

               size = s;
               width = w;
               height = h;

               keys = new Key[s+1];

               for ( int n = 1; n <= s; n++ )
               {
                  keys[n] = new Key(h,w);
               };

               for ( int i = 1; i <= s; i++ )
               {
                  add( keys[i] );
               };

               draw();
            }

            public void draw()
            {

               for ( int n = 1; n <= size; n++ )
               {
                 keys[n].draw();
               };
               frameit();
            }
              
            public Insets insets()
            {
              return new Insets(15,15,15,15);
            }

            public void frameit()
            {
               blue.shapes.Rectangle frame;
               for ( int i = 1; i <=5; i++ )
               {
                 frame = new blue.shapes.Rectangle(height+i,size*width+i);
                 draw(frame);
               };
            }


         }

         class KeyboardBuffer extends Panel
         {
            KeyboardBuffer(Keyboard k)
            {
               setLayout(new GridBagLayout());
               add(k);
            }
         }

