Skip to content

Commit 214c3e0

Browse files
committed
Added sounds to turtles
1 parent 9ca4f48 commit 214c3e0

4 files changed

Lines changed: 161 additions & 109 deletions

File tree

src/main/java/org/teachingextensions/logo/Sound.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
package org.teachingextensions.logo;
22

3-
import java.awt.Toolkit;
4-
import java.net.URL;
5-
63
import javax.sound.sampled.AudioInputStream;
74
import javax.sound.sampled.AudioSystem;
85
import javax.sound.sampled.Clip;
6+
import java.awt.*;
7+
import java.net.URL;
98

109
/**
1110
* <img src="http://www.spellzone.com/images/sound-icon.gif" style="text-align: left" alt="A speaker with sound waves" >
12-
* Sound allows you to play a sound, like a 'beep' or the sound from a file
11+
* Sound allows you to play a sound, like a 'beep' or the sound from a file
1312
*/
1413
public class Sound
14+
1515
{
16+
private URL soundUrl = null;
17+
18+
public Sound() {
19+
this(TKPSound.Yay);
20+
}
21+
22+
public Sound(TKPSound sound) {
23+
this.setSound(sound);
24+
}
25+
1626
/**
1727
* Plays a beep through your speakers. BEEP!<br>
1828
* <b>Example:</b> {@code Sound.playBeep()}
@@ -21,16 +31,9 @@ public static void playBeep()
2131
{
2232
Toolkit.getDefaultToolkit().beep();
2333
}
34+
2435
/**
25-
* Check out our cool sounds - thanks to http://www.wavsource.com/
26-
*/
27-
public enum TKPSound {
28-
Ahem, Applause, BrainIsGone, CatMeow, Cheering, Crickets, DoctorMccoy, Fanfare, FargoYah, Gong, LLCoolJYaKnow,
29-
LosingPower, Malfunction, Pizza, RunAway, SheerIgnorance, SoBeIt, StrangePerson, Stubborn, Yahoo, Yay
30-
}
31-
private URL soundUrl = null;
32-
/**
33-
* Sets a sound that you can play through your speakers.
36+
* Sets a sound that you can play through your speakers.
3437
* Use a TKPSound (there is a list)<br>
3538
* <b>Example:</b> {@code Sound.setSound(TKPSound.Ahem)}
3639
*/
@@ -45,8 +48,9 @@ public synchronized void setSound(TKPSound mySound)
4548
if (resource == null) { throw new IllegalStateException("Could not get TKPSound: " + sound); }
4649
this.soundUrl = resource;
4750
}
51+
4852
/**
49-
* Plays a TKPSound through your speakers.
53+
* Plays a TKPSound through your speakers.
5054
* You must first set the TKPSound <br>
5155
* <b>Example:</b> {@code Sound.playSound()}
5256
*/
@@ -72,4 +76,11 @@ public void run()
7276
}
7377
}).start();
7478
}
79+
/**
80+
* Check out our cool sounds - thanks to http://www.wavsource.com/
81+
*/
82+
public enum TKPSound {
83+
Ahem, Applause, BrainIsGone, CatMeow, Cheering, Crickets, DoctorMccoy, Fanfare, FargoYah, Gong, LLCoolJYaKnow,
84+
LosingPower, Malfunction, Pizza, RunAway, SheerIgnorance, SoBeIt, StrangePerson, Stubborn, Yahoo, Yay
85+
}
7586
}

0 commit comments

Comments
 (0)