Kleine aanpassingen gemaakt aan (Lan)TextDevice

This commit is contained in:
Bram Veenboer
2011-02-15 21:28:00 +00:00
parent e078b1c3d0
commit 19fa8d34dd
3 changed files with 17 additions and 27 deletions

View File

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

View File

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

View File

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