File tree Expand file tree Collapse file tree
main/java/org/teachingextensions
test/java/org/teachingextensions/logo/utils/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .teachingextensions .logo .utils ;
2+
3+ import java .awt .Toolkit ;
4+ import java .io .File ;
5+
6+ import javax .sound .sampled .AudioInputStream ;
7+ import javax .sound .sampled .AudioSystem ;
8+ import javax .sound .sampled .Clip ;
9+
10+ /**
11+ * <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
13+ */
14+ public class Sound
15+ {
16+ /**
17+ * Plays a beep through your speakers. BEEP!<br>
18+ * <b>Example:</b> {@code Sound.playBeep()}
19+ */
20+ public static void playBeep ()
21+ {
22+ Toolkit .getDefaultToolkit ().beep ();
23+ }
24+ /**
25+ * Plays a sound through your speakers. Use a '.wav' file<br>
26+ * <b>Example:</b> {@code Sound.playSound("mySound.wav")}
27+ */
28+ public static synchronized void playSound (final String fileName )
29+ {
30+ new Thread (new Runnable ()
31+ {
32+ @ Override
33+ public void run ()
34+ {
35+ try
36+ {
37+ Clip clip = AudioSystem .getClip ();
38+ AudioInputStream inputStream = AudioSystem .getAudioInputStream (new File (fileName ));
39+ clip .open (inputStream );
40+ clip .start ();
41+ }
42+ catch (Exception e )
43+ {
44+ System .out .println ("play sound error: " + e .getMessage () + " for " + fileName );
45+ }
46+ }
47+ }).start ();
48+ }
49+ }
Load diff This file was deleted.
Original file line number Diff line number Diff line change @@ -20,11 +20,11 @@ public class Parser
2020 * <div><b>Example:</b><pre>{@code
2121 * Words data = new Words();
2222 * data.action = "Shake";
23- * data.weapon = "spear ";
23+ * data.weapon = "speare ";
2424 * String greeting = Parser.parse("Captain {action}{weapon}!!!", data);
2525 * }</pre></div>
2626 *
27- * Captain Shakespear !!!
27+ * Captain Shakespeare !!!
2828 *
2929 * @param text
3030 * The template with the fields from the data object surrounded in {curlyBraces}
Original file line number Diff line number Diff line change 22
33import junit .framework .TestCase ;
44
5- import org .teachingextensions .logo .utils .Sounds ;
5+ import org .teachingextensions .logo .utils .Sound ;
66
77public class SoundsDemo extends TestCase
88{
99 public void testBeep () throws Exception
1010 {
11- Sounds .playBeep ();
11+ Sound .playBeep ();
1212 }
1313}
You can’t perform that action at this time.
0 commit comments