java - How do I reach the running instance of my Thread? -


basically, have class called playback extends thread. want able run functions have defined class thread object, when have no affect on current thread of said object. can functions work when called if .run() instead of .start() causes gui freeze up. here code

playback function = new playback(list, progbar, settings); function.start(); function.terminate(); 

the above code not work below does

playback function = new playback(list, progbar, settings); function.run() function.terminate();    

when use run though causes gui freeze. how call methods on running thread?

here playback class:

package chronos.functions;  import java.awt.robot; import java.awt.event.inputevent; import java.util.list; import javafx.scene.control.progressbar; import chronos.graphics.inputvalue;  public class playback extends thread {     list<inputvalue> list;     progressbar progbar;     settings settings;     boolean terminated = false;     public playback(list<inputvalue> list, progressbar progbar, settings settings) {         this.list = list;         this.progbar = progbar;         this.settings = settings;     }     public void run() {     try {         robot bot = new robot();         double x = settings.getcyclenumbers();         thread.sleep(settings.initialdelay);         (double c = 0; c <= x; c++) {             if (terminated == false) {                 system.out.println(terminated);                 system.out.println(isinterrupted());             progbar.setprogress(c/x);              if (list.isempty() != true) {             (inputvalue i: list) {                 if (terminated == false) {                 if (i.gettype() == "key") {                 long longruntime = system.currenttimemillis();                 if (settings.recdurations == true) {                     if (i.getduration() > 0) {                         while(i.getduration() > system.currenttimemillis() - longruntime ) {                             bot.keypress(i.getcode());                         }                 } else {                      bot.keypress(i.getcode());                  }                 } else {                     if (settings.getdurationtime() > 0) {                         while(settings.getdurationtime() > system.currenttimemillis() - longruntime ) {                             bot.keypress(i.getcode());                         }                 } else {                     bot.keypress(i.getcode());                  }             }             } else {                 bot.mousepress(inputevent.button1_down_mask);                 if (settings.recdurations == true) {                     thread.sleep(i.getduration());                 } else {                     thread.sleep(settings.getdurationtime());                 }                 bot.mouserelease(inputevent.button1_down_mask);                 if (settings.recpositions == true) {                 bot.mousemove(i.getx(), i.gety());                 }              }             if (settings.trackdelay == true) {             thread.sleep(i.getdelay());             } else {                 thread.sleep(settings.getkeydelay());             }         } else {             break;         }         thread.sleep(settings.cycledelay);         }              } else {                 progbar.setprogress(0);             }         } else {             break;         }         }     } catch (exception ex) {         ex.printstacktrace();     }     }     public void terminate() {         system.out.println("terminated");         terminated = true;     } } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -