In this section we make an ActionListener for our JButton and put inside ONE line of code to make a sound. Here's the start of the JButton's ActionListener as usual this is pretty straight forward:
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Now, ladies and gentleman the code you've all been waiting for:
mc[5].noteOn(60,600);
That makes the sound in an arbitrary MidiChannel that I picked (The standard number of Midi channels
is 16 so ya know!). I don't know the difference of the Midi Channels. To make the sound we just turn
on a note with the noteOn method. The 60 is the note number (middle C) and 600 is how hard we
hit the piano key or plucked the instrument's string (you get the idea). There is also a noteOff
method but as far as I can tell the sound dies off all by itself. Here's some finish up code: }
} ); // END OF THE ACTION LISTENER
} // END OF THE MAIN METHOD
Isn't that neet? Here's some thing to try:
I hope you have fun, Note: If you like this let me know and I'll learn somemore to teach ya!
Comments