public void mouseReleased(MouseEvent e)
  {
    mouseReleasedX = e.getX();
    
    if(mouseDragged)
    {
      
      mousePressed = mousePressedX;
      mouseReleased = mouseReleasedX;
      
      if (mousePressed > mouseReleased)//selected right to left
      {
        int temp = mousePressed;
        mousePressed = mouseReleased;
        mouseReleased = temp;
      }
      
      startFrame = (int)(mousePressed * framesPerPixel);
      stopFrame = (int)(mouseReleased * framesPerPixel);
      
      //stopped dragging outside the window.
      if(stopFrame >= sound.getLengthInFrames()) 
        stopFrame = sound.getLengthInFrames();
      
      //stopped dragging outside the window
      if(startFrame < 0)
        startFrame = 0;
      
      //new values for the labels
      startIndexLabel.setText(startIndexText + (startFrame));
      stopIndexLabel.setText(stopIndexText + (stopFrame));
      
      //for highlighting the selection
      selectionStart = mousePressed;
      selectionStop = mouseReleased;
      
      soundPanel.repaint();
      playSelectionButton.setEnabled(true);
      clearSelectionButton.setEnabled(true);
      mouseDragged = false;
    }
    
  }