Add pause method in InputListener
- Pause method and var to stop Scanner from 'taking' the input when in menue.
This commit is contained in:
parent
bd68322a75
commit
6d3d3b5085
@ -6,6 +6,7 @@ public class InputListener implements Runnable {
|
||||
private volatile boolean hasNew;
|
||||
private final Scanner in;
|
||||
private boolean stop;
|
||||
private boolean pause;
|
||||
|
||||
public InputListener() {
|
||||
in = new Scanner(System.in);
|
||||
@ -14,8 +15,15 @@ public class InputListener implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while(!stop) {
|
||||
input = in.next();
|
||||
hasNew = true;
|
||||
if (!pause){
|
||||
input = in.next();
|
||||
hasNew = true;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("Stopped input listener");
|
||||
}
|
||||
@ -32,4 +40,12 @@ public class InputListener implements Runnable {
|
||||
public boolean hasNew() {
|
||||
return hasNew;
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
pause = true;
|
||||
}
|
||||
|
||||
public void unpause() {
|
||||
pause = false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user