title: Issue with MultiThreading and sound
body: <p>After looking online, I found simple examples of a class that shows three or so threads working simultaneously. But I cannot seem to incorporate this into my program. I am making a sound board that utilizes keys 1-9 on the number pad, and is supposed to play a sound bit when pressed, but still allowing other keys to initiate sounds being pressed or recognizing its been released and stop playing. But even though (I think) i have a multi thread system set up, one thread takes complete control of the program, playing one audio file to completion. </p>
  
  <p>Here is the meat of the program: a simple Frame  that implements Runnable, and is created and started in the Launcher class. It has "circle" objects that display a red circle in the place of the number pad on the frame, and changes to blue if the corresponding number is pressed. It also contains a SoundButton ArrayList that implements Runnable.</p>
  
  <p>Frame:</p>
  
  <pre><code>public class Frame extends JFrame implements Runnable{
  private static final long serialVersionUID = 1L;
  private Pane pane;
  private ArrayList&lt;Circle&gt; c;
  private ArrayList&lt;SoundButton&gt; SB;
  private KeyManager keyManager;
  
  public Frame(ArrayList&lt;SoundButton&gt; soundButton){
  
      keyManager = new KeyManager();
      this.addKeyListener(keyManager);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      this.getContentPane().setPreferredSize(new Dimension(400, 400));
      this.pack();
      this.setLocationRelativeTo(null);
  
      pane = new Pane();
      this.add(pane);
  
      c = new ArrayList&lt;Circle&gt;();
      SB = soundButton;
  
      c.add(new Circle(20, 140));
      c.add(new Circle(80, 140));
      c.add(new Circle(140, 140));
      c.add(new Circle(20, 80));
      c.add(new Circle(80, 80));
      c.add(new Circle(140, 80));
      c.add(new Circle(20, 20));
      c.add(new Circle(80, 20));
      c.add(new Circle(140, 20));
  
      this.setVisible(true);
  }
  
  public void init(){
      pane.draw(c);
  }
  
  public void update(){
      pane.draw(c);
      keyManager.update();
      if(keyManager.isNine()){
          c.get(8).press();
          SB.get(0).start();
      }
      else{
          c.get(8).release();
          SB.get(0).stop();
      }
      if(keyManager.isEight()){
          c.get(7).press();
          SB.get(1).start();
      }
      else{
          c.get(7).release();
          SB.get(1).stop();
      }
      if(keyManager.isSeven()){
          c.get(6).press();
      }
      else{
          c.get(6).release();
      }
      if(keyManager.isSix()){
          c.get(5).press();
      }
      else{
          c.get(5).release();
      }
      if(keyManager.isFive()){
          c.get(4).press();
      }
      else{
          c.get(4).release();
      }
      if(keyManager.isFour()){
          c.get(3).press();
      }
      else{
          c.get(3).release();
      }
      if(keyManager.isThree()){
          c.get(2).press();
      }
      else{
          c.get(2).release();
      }
      if(keyManager.isTwo()){
          c.get(1).press();
      }
      else{
          c.get(1).release();
      }
      if(keyManager.isOne()){
          c.get(0).press();
      }
      else{
          c.get(0).release();
      }
  }
  
  
  public void run() {
  
      init();
  
      int fps = 60;
      double timePerUpdate = 1000000000/fps;
      double delta = 0;
      long now;
      long lastTime= System.nanoTime();
      long timer = 0;
      int updates = 0;
  
      while(true){
          now = System.nanoTime();
          delta += (now - lastTime) / timePerUpdate;
          timer+= now - lastTime; 
          lastTime = now;
  
          if(delta &gt;= 1){
              update();
              updates ++;
              delta--;
          }
  
          if(timer &gt;= 1000000000){
              //System.out.println("Updates and Frames: "+ updates);
              updates = 0;
              timer = 0;
          }
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>SoundButton:</p>
  
  <pre><code>public class SoundButton implements Runnable{
  
  private AudioPlayer sound;
  private boolean running = false;
  private Thread thread;
  
  public SoundButton(String path){
      sound = new AudioPlayer(path);
  }
  @Override
  public void run() {
  
  }
  
  public synchronized void start(){
      if(running){
          return; 
      }
      else{
      running = true;
      thread = new Thread(this);
      thread.start();
      sound.play();
      }
  }
  
  public synchronized void stop(){
      if(!running)
          return; 
      running = false;
      sound.stop();
      try {
          thread.join();
      } catch (InterruptedException e) {
  
          e.printStackTrace();
      }
  
  
  }
  
  }
  </code></pre>
  
  <p>Launcher:</p>
  
  <pre><code>public class Launcher {
  
  
  public static void main(String[] args){
      ArrayList&lt;SoundButton&gt; SB = new ArrayList&lt;SoundButton&gt;();
      SB.add(new SoundButton("/sound/sound1.mp3"));
      SB.add(new SoundButton("/sound/sound2.mp3"));
      Frame f = new Frame(SB);
      Thread t = new Thread(f);
      t.start();
  
  }
  
  }
  </code></pre>
  
  <p>and if it is needed, my AudioPlayer class:</p>
  
  <pre><code>public class AudioPlayer 
  </code></pre>
  
  <p>{<br>
      private Clip clip;</p>
  
  <pre><code>public AudioPlayer(String s)
  {
      try
      {
          AudioInputStream ais = AudioSystem.getAudioInputStream(
                                  getClass().getResourceAsStream(s));
  
              AudioFormat baseFormat = ais.getFormat();
              AudioFormat decodeFormat = new AudioFormat(
                      AudioFormat.Encoding.PCM_SIGNED,
                      baseFormat.getSampleRate(),
                      16,
                      baseFormat.getChannels(),
                      baseFormat.getChannels() * 2,
                      baseFormat.getSampleRate(),
                      false
                      );
  
          AudioInputStream dais = AudioSystem.getAudioInputStream(
                                  decodeFormat, ais);
          clip = AudioSystem.getClip();
          clip.open(dais);
  
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }   
  }
  
  public void play()
  {
      if (clip == null)
      {
          System.out.print("null");
          return;
      }
      stop();
      clip.setFramePosition(0);
      clip.start();
      System.out.println("Drain...");
      clip.drain();
      System.out.println("...Drained");
  }
  public void stop()
  {
      if (clip.isRunning())
      {
          clip.stop();
      }
  }
  public void close()
  {
      stop();
      clip.close();
  }
  
  }
  </code></pre>