Kleine aanpassingen gemaakt aan (Lan)TextDevice
This commit is contained in:
@@ -7,18 +7,14 @@ import pm.Device;
|
||||
public class LanTextDevice extends Device implements Runnable {
|
||||
static final int PORT = 1234;
|
||||
|
||||
ServerSocket socket;
|
||||
protected ServerSocket socket;
|
||||
|
||||
public LanTextDevice() {
|
||||
public void initialise() {
|
||||
try {
|
||||
socket = new ServerSocket(PORT);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
initialise();
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import pm.Target;
|
||||
import pm.Task;
|
||||
import pm.task.TaskGatherer;
|
||||
|
||||
public class LanTextListener implements Runnable{
|
||||
static final int SLEEP = 50;
|
||||
public class LanTextListener implements Runnable {
|
||||
static final int SLEEP = 100;
|
||||
|
||||
protected boolean run;
|
||||
protected Socket socket;
|
||||
@@ -19,7 +19,7 @@ public class LanTextListener implements Runnable{
|
||||
public LanTextListener(Socket socket){
|
||||
this.socket = socket;
|
||||
try {
|
||||
this.input = new Scanner(socket.getInputStream());
|
||||
input = new Scanner(socket.getInputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -28,13 +28,13 @@ public class LanTextListener implements Runnable{
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(run && socket.isConnected() && input.hasNext()) {
|
||||
while (run && socket.isConnected() && input.hasNext()) {
|
||||
String textinput = input.next().toUpperCase();
|
||||
if(textinput != null) {
|
||||
try {
|
||||
TaskGatherer.add(
|
||||
new Task(Action.valueOf(textinput), Target.APPLICATION));
|
||||
} catch(IllegalArgumentException e) { }
|
||||
new Task(Action.valueOf(textinput), Target.APPLICATION));
|
||||
} catch (IllegalArgumentException e) {}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
|
||||
@@ -9,31 +9,25 @@ import pm.Task;
|
||||
import pm.task.TaskGatherer;
|
||||
|
||||
public class TextDevice extends Device implements Runnable {
|
||||
static final int SLEEP = 50;
|
||||
|
||||
static final int SLEEP = 100;
|
||||
|
||||
protected boolean run;
|
||||
protected Scanner input;
|
||||
|
||||
public TextDevice() {
|
||||
initialise();
|
||||
run = true;
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
|
||||
public void initialise() {
|
||||
input = new Scanner(System.in);
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
System.out.println("TextDevice activated");
|
||||
while(run) {
|
||||
run = true;
|
||||
while (run) {
|
||||
String textinput = input.next().toUpperCase();
|
||||
if(textinput != null) {
|
||||
System.out.println(textinput);
|
||||
try {
|
||||
TaskGatherer.add(
|
||||
new Task(Action.valueOf(textinput), Target.APPLICATION));
|
||||
} catch(IllegalArgumentException e) { }
|
||||
new Task(Action.valueOf(textinput), Target.APPLICATION));
|
||||
} catch(IllegalArgumentException e) {}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
|
||||
Reference in New Issue
Block a user