title: Pass a process to a subclass
body: <p>I would like to pass a process to a subclass so I may kill it but I can't figure out how to pass the process. I'm unsure how to store it so I can return it to the form and be able to call the subclass method to kill it. here are my classes</p>
  
  <pre><code>package my.mashformcnts;
  import java.io.IOException;
  import java.util.Scanner;
  import java.util.regex.Pattern;
  
  
  /**
   *
   * @author brett
   */
  public class MashRocks {
  
      public static Process startThread(MashFormCnts mashFormCnts) throws IOException {
          ProcessBuilder pb = new ProcessBuilder("ffmpeg", "-i", "C:\\Users\\brett\\Documents\\Telegraph_Road.mp4", "C:\\Users\\brett\\Documents\\out.mp4");
  
          //Here is where i would like to name and store the Process
  
  
          final Process p = pb.start();
          // create a new thread to get progress from ffmpeg command , override  
          // it's run method, and start it!  
          Thread t = new Thread() {
              @Override
              public void run() {
                  Scanner sc = new Scanner(p.getErrorStream());
                  // Find duration  
                  Pattern durPattern = Pattern.compile("(?&lt;=Duration: )[^,]*");
                  String dur = sc.findWithinHorizon(durPattern, 0);
                  if (dur == null) {
                      throw new RuntimeException("Could not parse duration.");
                  }
                  String[] hms = dur.split(":");
                  double totalSecs = Integer.parseInt(hms[0]) * 3600 + Integer.parseInt(hms[1]) * 60 + Double.parseDouble(hms[2]);
                  System.out.println("Total duration: " + totalSecs + " seconds.");
                  // Find time as long as possible.  
                  Pattern timePattern = Pattern.compile("(?&lt;=time=)[\\d:.]*");
                  String match;
                  String[] matchSplit;
                  //MashForm pgbar = new MashForm();
                  while (null != (match = sc.findWithinHorizon(timePattern, 0))) {
                      matchSplit = match.split(":");
                      double progress = (Integer.parseInt(matchSplit[0]) * 3600 + Integer.parseInt(matchSplit[1]) * 60 + Double.parseDouble(matchSplit[2])) / totalSecs;
                      int prog = (int) (progress * 100);
                      mashFormCunts.setbar(prog);
                  }
              }
          };
         t.start();
         return p;
      }
     public synchronized static void stop(Thread t) throws IOException{
             Runtime.getRuntime().exec("taskkill /F /IM ffmpeg.exe");  
              t = null;
            //t.interrupt();
  
  
  
     }
  }
     class killMash extends MashRocks{
      public static void Kfpeg(Process p){
  
        p.destroyForcibly();
      }
  }
  </code></pre>
  
  <p>So those are my classes. I'm very new.</p>
  
  <p>Next there is the event Listener on the form, so when I click this I want to kill the ffmpeg proecess with the <code>Thread t</code>:</p>
  
  <pre><code>  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          // TODO add your handling code here:
          Thread n = Thread.currentThread();
          System.out.print(n);
          try {
              //MashRocks.stop(n);
               //This isnt working but i think its closer
               killMash.Kfpeg(MashRocks.startThread(this)); 
  //Not Sure what to do here
    //here is where i want to pass the process sorry for the typo
    killMash.kfpeg(p); 
              } catch (IOException ex) {
                  Logger.getLogger(MashFormCunts.class.getName()).log(Level.SEVERE, null, ex);
              }
  
          }   
  </code></pre>
  
  <p>Any help is awesome cheers</p>