P.37 (Add All 12 White Keys)


public Piano() {
  super(800, 340, 1);
  // Width of piano: 800
  // Width of 12 keys: 12 * 63 = 756
  // Empty space = 800 - 756 = 44
  // Half the space on each side = 44 / 2 = 22
  for(int i=0; i<12; i++)
    addObject( new Key("g", "3a.wav"), 
               22 + 32 + i*63, 140 );
}
Last modified on
Engineering DIY Workshop 2018