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 volatile boolean hasNew;
|
||||||
private final Scanner in;
|
private final Scanner in;
|
||||||
private boolean stop;
|
private boolean stop;
|
||||||
|
private boolean pause;
|
||||||
|
|
||||||
public InputListener() {
|
public InputListener() {
|
||||||
in = new Scanner(System.in);
|
in = new Scanner(System.in);
|
||||||
@ -14,9 +15,16 @@ public class InputListener implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(!stop) {
|
while(!stop) {
|
||||||
|
if (!pause){
|
||||||
input = in.next();
|
input = in.next();
|
||||||
hasNew = true;
|
hasNew = true;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
System.out.println("Stopped input listener");
|
System.out.println("Stopped input listener");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,4 +40,12 @@ public class InputListener implements Runnable {
|
|||||||
public boolean hasNew() {
|
public boolean hasNew() {
|
||||||
return hasNew;
|
return hasNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
pause = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unpause() {
|
||||||
|
pause = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user