1302 Java Media (Affordable web design) Framework and Java Sound (on
1302 Java Media Framework and Java Sound (on CD) Chapter 22 105 // set correct spacing for buttons 106 noteButton[ i ].setBounds( ( i * 11 ), 1, 11, 40 ); 107 keyPanel.add( noteButton[ i ] ); 108 109 // register a mouse listener for mouse events 110 noteButton[ i ].addMouseListener( 111 112 // anonymous inner class to handle mouse events 113 new MouseAdapter() { 114 115 // invoke key note when mouse touches key 116 public void mouseEntered( MouseEvent mouseEvent ) 117 { 118 // if recording, send message to receiver 119 if ( recording ) 120 midiSynthesizer.sendMessage( 121 ShortMessage.NOTE_ON, 122 note + FIRST_NOTE, midiVolume ); 123 124 // else just sound the note 125 else 126 midiSynthesizer.midiNoteOn( 127 note + FIRST_NOTE, midiVolume ); 128 129 // turn key color to blue 130 noteButton[ note ].setBackground( 131 Color.blue ); 132 } 133 134 // turn key note off when mouse leaves key 135 public void mouseExited( MouseEvent mouseEvent ) 136 { 137 if ( recording ) 138 midiSynthesizer.sendMessage( 139 ShortMessage.NOTE_OFF, 140 note + FIRST_NOTE, midiVolume ); 141 else 142 midiSynthesizer.midiNoteOff( 143 note + FIRST_NOTE ); 144 145 noteButton[ note ].setBackground( 146 Color.white ); 147 } 148 149 } // end MouseAdapter 150 151 ); // end call to addMouseListener 152 153 } // end for loop 154 155 } // end method makeKeys 156 Fig. 22.10 MidiDemoprovides the GUI than enables users to interact with the application (part 3 of 14).
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.