home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 April / comcd0402.iso / homepage / javaspecial / 07_01 / Note.java < prev    next >
Encoding:
Java Source  |  1999-07-16  |  1.1 KB  |  55 lines

  1. import java.applet.*;
  2.  
  3. /**
  4.  * This class is for a musical note or sound that can be played continuously, or silenced.
  5.  * 
  6.  * @author David Rantanen
  7.  * @version 1999 July 16
  8.  */ 
  9.  
  10. public class Note
  11. {
  12.     /** The sound to be played
  13.     */
  14.     private AudioClip tone;
  15.     
  16.     /** Whether the sound is currently playing
  17.     */
  18.     private boolean playing;
  19.     
  20.     /**      Constructs Note object
  21.      * @param      sound  A sound to be used as a note
  22.      */             
  23.     public Note(AudioClip sound)
  24.     {
  25.         playing=false;
  26.         tone=sound;
  27.     }
  28.     
  29.     /**
  30.      * Tells whether the note is currently playing
  31.      * 
  32.      * @return true if it's playing, false otherwise.
  33.      */             
  34.     public boolean isPlaying()
  35.     {
  36.         return playing;
  37.     }
  38.     
  39.     /**  Starts the note continuously playing
  40.      */             
  41.     public void play()
  42.     {
  43.         tone.loop();
  44.         playing=true;
  45.     }
  46.     
  47.     /**  Stops the note.
  48.      */             
  49.     
  50.     public void stop()
  51.     {
  52.         tone.stop();
  53.         playing=false;
  54.     }
  55. }