My Runnable!
anyhelp it only prints out the seconds not what i print out here
LooterTimer timeTast1 = new LooterTimer(10, new Runnable(){
@Override
public void run() {
System.out.println("200"); <-- I WANT THIS TO PRINT OUT!
}
});
LooterTimer
package my.tdl.managers;
public class LooterTimer implements Runnable{
private int defaultSeconds;
private int seconds;
private boolean hasCompleted;
private boolean running;
private Thread thread;
public LooterTimer(int seconds, Runnable runnable) {
this.seconds = seconds;
this.defaultSeconds = seconds;
start();
}
@Override
public void run() {
if(!running){
running = true;
}
while(running){
if(seconds != 0){
System.out.println(seconds+" seconds left!"); <-- already printing!
seconds -= 1;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(seconds == 0){
stop();
}
}
}
public void stop() {
running = false;
hasCompleted = true;
seconds = defaultSeconds;
thread.stop();
}
public void start() {
running = false;
hasCompleted = false;
seconds = defaultSeconds;
if(thread == null){
thread = new Thread(this);
thread.start();
}
}
public boolean isRunning() {
return running;
}
public boolean hasCompleted() {
return hasCompleted;
}
}