title: Java Sound API - capturing microphone
body: <p>I have been reading up on the Sound API for Java for a couple of days I am unable to make sense of it. I am decent programmer, I just having difficulty getting my head around the API. </p>
  
  <p>I have been trying to capture audio from my microphone and display a wave graph in real time. </p>
  
  <p>I am having trouble capturing audio, they say in the tutorial to do this, but I cant seem to get it to work. </p>
  
  <p>Any suggestions and help would be much appreciated, a line by line answer would be ideal.</p>
  
  <p>Please and thank you. </p>
  
  <pre><code>import javax.sound.sampled.AudioFormat;
  import javax.sound.sampled.AudioSystem;
  import javax.sound.sampled.DataLine;
  import javax.sound.sampled.LineUnavailableException;
  import javax.sound.sampled.TargetDataLine;
  
  public class FindLine {
  
   public static void main (String[] args){
  
    AudioFormat format = new AudioFormat(22000,16,2,true,true);
    TargetDataLine line;
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, 
        format); // format is an AudioFormat object
    if (!AudioSystem.isLineSupported(info)) {
        // Handle the error ... 
    }
    // Obtain and open the line.
    try {
        line = (TargetDataLine) AudioSystem.getLine(info);
        line.open(format);
    } catch (LineUnavailableException ex) {
        // Handle the error ... 
    }
   }
  
  }
  </code></pre>