java - How can I set this thread instead of starting it from 0? -


i have class works clock, follows:

public class playtime extends thread {  public int playtimei = 0; @override public void run() {     while(true)     {         playtimei++;         try {             thread.sleep(1000);         } catch (interruptedexception e) {             e.printstacktrace();         }     } } } 

which, in new game program started this:

data.playtime = new playtime(); data.playtime.start(); 

which causes start zero; however, game needs able read int save file , start number instead.

how start specific int?

i think simple read config time , in class add constructor playtime.

public class playtime extends thread {      int playtimei = 0;      public playtime(int playtimei) {         this.playtimei = playtimei;     }     @override     public void run() {         while(true)         {             playtimei++;             try {                 thread.sleep(1000);             } catch (interruptedexception e) {                 e.printstacktrace();             }         }     } } 

and call like:

int time = loadfromfile(); playtime playtime = new playtime(time); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -