home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap27 / SoundApplet2.java < prev    next >
Encoding:
Java Source  |  1996-03-13  |  952 b   |  43 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3. import java.net.*;
  4.  
  5. public class SoundApplet2 extends Applet
  6. {
  7.     AudioClip soundClip;
  8.  
  9.     public void init()
  10.     {
  11.         GridLayout layout = new GridLayout(1, 3, 10, 10);
  12.         setLayout(layout);
  13.  
  14.         Font font = new Font("TimesRoman", Font.BOLD, 24);
  15.         setFont(font);
  16.  
  17.         Button button = new Button("Play");
  18.         add(button);
  19.         button = new Button("Stop");
  20.         add(button);
  21.         button = new Button("Loop");
  22.         add(button);
  23.  
  24.         URL codeBase = getCodeBase();
  25.         soundClip = getAudioClip(codeBase, "spacemusic.au");
  26.  
  27.         resize(250, 250);
  28.     }
  29.  
  30.     public boolean action(Event evt, Object arg)
  31.     {
  32.         if (arg == "Play")
  33.             soundClip.play();
  34.         else if (arg == "Stop")
  35.             soundClip.stop();
  36.         else if (arg == "Loop")
  37.             soundClip.loop();
  38.  
  39.         return true;
  40.     }
  41. }
  42.  
  43.