11package org .teachingextensions .logo ;
22
33import java .awt .Toolkit ;
4- import java .io .File ;
54import java .net .URL ;
65
76import javax .sound .sampled .AudioInputStream ;
@@ -29,7 +28,7 @@ public enum TKPSound {
2928 Ahem , Applause , BrainIsGone , CatMeow , Cheering , Crickets , DoctorMccoy , Fanfare , FargoYah , Gong , LLCoolJYaKnow ,
3029 LosingPower , Malfunction , Pizza , RunAway , SheerIgnorance , SoBeIt , StrangePerson , Stubborn , Yahoo , Yay
3130 }
32- private String soundFilename = null ;
31+ private URL soundUrl = null ;
3332 /**
3433 * Sets a sound that you can play through your speakers.
3534 * Use a TKPSound (there is a list)<br>
@@ -44,8 +43,7 @@ public synchronized void setSound(TKPSound mySound)
4443 resource = this .getClass ().getClassLoader ().getResource (sound );
4544 }
4645 if (resource == null ) { throw new IllegalStateException ("Could not get TKPSound: " + sound ); }
47- this .soundFilename = resource .toString ();
48- this .soundFilename = this .soundFilename .replace ("file:" , "" );
46+ this .soundUrl = resource ;
4947 }
5048 /**
5149 * Plays a TKPSound through your speakers.
@@ -54,7 +52,7 @@ public synchronized void setSound(TKPSound mySound)
5452 */
5553 public synchronized void playSound ()
5654 {
57- final String sound = this .soundFilename ;
55+ final URL sound = this .soundUrl ;
5856 new Thread (new Runnable ()
5957 {
6058 @ Override
@@ -63,7 +61,7 @@ public void run()
6361 try
6462 {
6563 Clip clip = AudioSystem .getClip ();
66- AudioInputStream inputStream = AudioSystem .getAudioInputStream (new File ( sound ) );
64+ AudioInputStream inputStream = AudioSystem .getAudioInputStream (sound );
6765 clip .open (inputStream );
6866 clip .start ();
6967 }
0 commit comments