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

      // File:  Piano.java
      // Type:  java applet
      // Date:  Sun Jan  5, 1997
      // Name:  blue
      // Line:  (Piano V3) - Display a keyboard, with adjacent keys


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

      /*

         This time the Keyboard is "trapped" in a Panel with a 
         GridBagLayout, which evidently does not expand to fill its 
         surrounding Panel.

      */

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

         package development.piano.v3;

      // 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);

            }

         }


         class Key extends Painter
         {
            int width;
            int height;
            blue.shapes.Rectangle border;

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

            public void draw()
            {
               draw(border);
            }
               

         }

         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));

               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] );
               };

               validate();
               draw();
               repaint();
            }

            public void draw()
            {

               for ( int n = 1; n <= size; n++ )
               {
                 keys[n].draw();
               };
            }

         }

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

