/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import javax.swing.*; 

2. import java.awt.*; 

3. import java.awt.event.*; 

4. import java.applet.*; 

5. import java.net.URL

6.  

7. public class Sound 

8.     extends JApplet 

9.     implements ActionListener 

10.

11.   AudioClip aclip ; 

12.   JButton btn ; 

13.   boolean playing=false

14.  

15.   public void init() 

16.   { 

17.     Container cp = getContentPane() ; 

18.     cp.setBackground ( Color.cyan ) ; 

19.     btn = new JButton ( "--- Engage ! ---" ); 

20.     cp.setLayout( new FlowLayout() ); 

21.     cp.add ( btn ); 

22.     btn.addActionListener ( this ); 

23.  

24.     URL classloc = getCodeBase (); 

25.  

26.     aclip = getAudioClip 

27.       ( classloc, "likeamachine.au"  ) ; 

28.   } 

29.   public void actionPerformed ( ActionEvent ev ) 

30.   { 

31.     if ( ! playing ) 

32.     { 

33.       aclip.loop () ; 

34.  

35.       playing = true

36.       btn.setText ( "Enoughalready" ) ; 

37.       return

38.     } 

39.     playing = false

40.     btn.setText ( "Play it again, SEMM" ) ; 

41.     aclip.stop (); 

42.   } 

43.   public void stop () 

44.   { 

45.     aclip.stop(); 

46.   } 

47.   public void start () 

48.   { 

49.     if ( playing )  aclip.loop(); 

50.   } 

51.

52.