java - Pass a process to a subclass -


i pass process subclass may kill can't figure out how pass process. i'm unsure how store can return form , able call subclass method kill it. here classes

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 name , store process           final process p = pb.start();         // create new thread progress ffmpeg command , override           // it's run method, , start it!           thread t = new thread() {             @override             public void run() {                 scanner sc = new scanner(p.geterrorstream());                 // find duration                   pattern durpattern = pattern.compile("(?<=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 long possible.                   pattern timepattern = pattern.compile("(?<=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();     } } 

so classes. i'm new.

next there event listener on form, when click want kill ffmpeg proecess thread t:

  private void jbutton2actionperformed(java.awt.event.actionevent evt) {                                                  // todo add handling code here:         thread n = thread.currentthread();         system.out.print(n);         try {             //mashrocks.stop(n);              //this isnt working think closer              killmash.kfpeg(mashrocks.startthread(this));  //not sure here   //here want pass process sorry typo   killmash.kfpeg(p);              } catch (ioexception ex) {                 logger.getlogger(mashformcunts.class.getname()).log(level.severe, null, ex);             }          }    

any awesome cheers

i don't know why want make static if need 1 possibility store process class variable:

public class mashrocks {      protected static process process = null;      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");      final process p = pb.start();     mashrocks.process = p;     ....     } } 

your stop method be:

public synchronized static void stop() throws ioexception{     if(mashrocks.process != null)     {         mashrocks.process.destroy();     } } 

and sub class:

class killmash extends mashrocks{     public static void kfpeg() throws ioexception{         killmash.stop();     } } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -