Add pause method in InputListener

- Pause method and var to stop
    Scanner from 'taking' the input
    when in menue.
This commit is contained in:
HeshamTB 2020-11-27 18:38:01 +03:00
parent bd68322a75
commit 6d3d3b5085
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -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;
}
}