home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 2.4 KB | 107 lines |
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.*;
-
- /*
- * the applet class
- */
- public class Guitar extends Applet implements ActionListener {
-
- /*
- * the guitar chords
- */
- AudioClip chords[] = new AudioClip[7];
-
- /*
- * the drum clip
- */
- AudioClip drum;
- String chordnames[] = {"a", "c", "d", "low_e", "high_e", "g", "chaa"};
- String drumbeat = "drum";
- Button chordbuttons[] = new Button[7];
- Button btnStart;
- Button btnStop;
- /*
- * Called when the applet is loaded
- * Load all sounds and add user interface
- */
- public void init () {
-
- String name;
- int i;
- Panel keyboard = new Panel();
- Panel controls = new Panel();
-
- this.setLayout(new BorderLayout());
- keyboard.setLayout(new FlowLayout());
- controls.setLayout(new FlowLayout());
- add ("Center", keyboard);
- add ("South", controls);
-
- for (i=0; i<7; i+=1) {
- name = chordnames[i]+".au";
- showStatus ("Getting " + name);
- chords[i] = getAudioClip (getCodeBase(), name);
- chordbuttons[i] = new Button (chordnames[i]);
- keyboard.add (chordbuttons[i]);
- chordbuttons[i].addActionListener(this);
- }
- showStatus ("Getting " + drumbeat + ".au");
- drum = getAudioClip (getCodeBase(), drumbeat + ".au");
- btnStart = new Button ("Start");
- controls.add (btnStart);
- btnStop = new Button ("Stop");
- controls.add (btnStop);
- btnStop.addActionListener(this);
- btnStart.addActionListener(this);
- }
-
- /*
- * Handle button presses
- * @param ev - event object
- * @param arg - target object
- */
- public void actionPerformed (ActionEvent ev)
- {
- Object object1 = ev.getSource();
- if (object1 == chordbuttons[0])
- {
- chords[0].play ();
- }
- else if (object1 == chordbuttons[1])
- {
- chords[1].play ();
- }
- else if (object1 == chordbuttons[2])
- {
- chords[2].play ();
- }
- else if (object1 == chordbuttons[3])
- {
- chords[3].play ();
- }
- else if (object1 == chordbuttons[4])
- {
- chords[4].play ();
- }
- else if (object1 == chordbuttons[5])
- {
- chords[5].play ();
- }
- else if (object1 == chordbuttons[6])
- {
- chords[6].play ();
- }
- else if (object1 == btnStart) {
- drum.loop ();
- }
- else if (object1 == btnStop)
- {
- drum.stop ();
- }
- }
- }
-
-
-
-