public void run()
    {
      while (thread != null && state == STATE_PLAYING && read != -1) {
        if (written >= read) {
          try {
            read = audioInputStream.read(buffer, 0, buffer.length);
            written = 0;
          }
          catch (IOException e) {
            e.printStackTrace();
          }
        }
        if (read > written) {
          int temp = line.write(buffer, written, read-written);
          written += temp;
        }
      }
      if (state == STATE_PLAYING) {
        /*
        Wait until all data are played. This is only necessary because of the
        bug noted below. (If we do not wait, we would interrupt the playback by
        prematurely closing the line and exiting the VM.)
        */
        line.drain();
        // All data are played. We can close the shop.
        line.close();
        stopButton.doClick();
      }
    }