Pause button works now
This commit is contained in:
parent
7d0d38c03c
commit
89b6a69516
@ -460,13 +460,14 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
|||||||
|
|
||||||
|
|
||||||
void pauseSim(){
|
void pauseSim(){
|
||||||
|
Globals.se.timer.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startSim(){
|
void startSim(){
|
||||||
resetSim();
|
resetSim();
|
||||||
this.startTraders();
|
this.startTraders();
|
||||||
Globals.se.timer.setAcceleration((Double)this.accelSpinner.getValue());
|
Globals.se.timer.setAcceleration((Double)this.accelSpinner.getValue());
|
||||||
|
Globals.se.timer.setPause(false);
|
||||||
Globals.se.timer.start();
|
Globals.se.timer.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ public class Scheduler extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getAcceleration() {
|
public double getAcceleration() {
|
||||||
|
|
||||||
return this.acceleration;
|
return this.acceleration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +112,11 @@ public class Scheduler extends Thread {
|
|||||||
|
|
||||||
// diff = 12199999L;
|
// diff = 12199999L;
|
||||||
last_time_millis += diff;
|
last_time_millis += diff;
|
||||||
|
|
||||||
|
if (pause) {
|
||||||
|
return (long) this.current_time_millis;
|
||||||
|
}
|
||||||
|
|
||||||
this.current_time_millis += diff * this.acceleration;
|
this.current_time_millis += diff * this.acceleration;
|
||||||
//System.out.printf("Current TM: %f\n", this.current_time_millis);
|
//System.out.printf("Current TM: %f\n", this.current_time_millis);
|
||||||
return (long) this.current_time_millis;
|
return (long) this.current_time_millis;
|
||||||
@ -151,13 +157,22 @@ public class Scheduler extends Thread {
|
|||||||
private boolean pause = false;
|
private boolean pause = false;
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
pause = !pause;
|
setPause(!pause);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPause(boolean val){
|
||||||
|
pause=val;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.notify();
|
this.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getPause(){
|
||||||
|
return pause;
|
||||||
|
}
|
||||||
|
|
||||||
public long fireEvent(TimerTask e) {
|
public long fireEvent(TimerTask e) {
|
||||||
return e.timerTask();
|
return e.timerTask();
|
||||||
}
|
}
|
||||||
@ -190,8 +205,9 @@ public class Scheduler extends Thread {
|
|||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
TimerTask e = it.next();
|
TimerTask e = it.next();
|
||||||
long next_t = this.fireEvent(e);
|
long next_t = this.fireEvent(e);
|
||||||
if (next_t == 0 )
|
if (next_t == 0) {
|
||||||
next_t++;
|
next_t++;
|
||||||
|
}
|
||||||
|
|
||||||
this.addEvent(e, next_t + t);
|
this.addEvent(e, next_t + t);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user