package com.BlossomAssociates.keyboard; import java.applet.AudioClip; import java.awt.event.*; /** * Plays a note. */ public class Sounder2 implements ActionListener, Runnable { private AudioClip note; private int volume = 0; public Sounder2( AudioClip theNote ) { if ( null == theNote ) { throw new IllegalArgumentException( "theNote may not be null." ); } this.note = theNote; } public void run() { while ( true ) { switch ( this.volume ) { case 0: try { this.note.stop(); Thread.sleep( 5L ); } catch ( InterruptedException ie ) {} break; default: case 10: this.note.loop(); } } } public void actionPerformed( ActionEvent ae ) { this.note.play(); } public void setVolume( int theLevel ) { if ( theLevel < 0 || 10 < theLevel ) { throw new IllegalArgumentException( "Volume levels must be from 0 to 10 inclusive." ); } this.volume = theLevel; } }