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 { public class LanTextDevice extends Device implements Runnable {
static final int PORT = 1234; static final int PORT = 1234;
ServerSocket socket; protected ServerSocket socket;
public LanTextDevice() { public void initialise() {
try { try {
socket = new ServerSocket(PORT); socket = new ServerSocket(PORT);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
initialise();
}
public void initialise() {
new Thread(this).start(); new Thread(this).start();
} }

View File

@@ -9,8 +9,8 @@ import pm.Target;
import pm.Task; import pm.Task;
import pm.task.TaskGatherer; import pm.task.TaskGatherer;
public class LanTextListener implements Runnable{ public class LanTextListener implements Runnable {
static final int SLEEP = 50; static final int SLEEP = 100;
protected boolean run; protected boolean run;
protected Socket socket; protected Socket socket;
@@ -19,7 +19,7 @@ public class LanTextListener implements Runnable{
public LanTextListener(Socket socket){ public LanTextListener(Socket socket){
this.socket = socket; this.socket = socket;
try { try {
this.input = new Scanner(socket.getInputStream()); input = new Scanner(socket.getInputStream());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -28,13 +28,13 @@ public class LanTextListener implements Runnable{
} }
public void run() { public void run() {
while(run && socket.isConnected() && input.hasNext()) { while (run && socket.isConnected() && input.hasNext()) {
String textinput = input.next().toUpperCase(); String textinput = input.next().toUpperCase();
if(textinput != null) { if(textinput != null) {
try { try {
TaskGatherer.add( TaskGatherer.add(
new Task(Action.valueOf(textinput), Target.APPLICATION)); new Task(Action.valueOf(textinput), Target.APPLICATION));
} catch(IllegalArgumentException e) { } } catch (IllegalArgumentException e) {}
} }
try { try {
Thread.sleep(SLEEP); Thread.sleep(SLEEP);

View File

@@ -9,31 +9,25 @@ import pm.Task;
import pm.task.TaskGatherer; import pm.task.TaskGatherer;
public class TextDevice extends Device implements Runnable { public class TextDevice extends Device implements Runnable {
static final int SLEEP = 50; static final int SLEEP = 100;
protected boolean run; protected boolean run;
protected Scanner input; protected Scanner input;
public TextDevice() {
initialise();
run = true;
new Thread(this).start();
}
public void initialise() { public void initialise() {
input = new Scanner(System.in); input = new Scanner(System.in);
new Thread(this).start();
} }
public void run() { public void run() {
System.out.println("TextDevice activated"); run = true;
while(run) { while (run) {
String textinput = input.next().toUpperCase(); String textinput = input.next().toUpperCase();
if(textinput != null) { if(textinput != null) {
System.out.println(textinput);
try { try {
TaskGatherer.add( TaskGatherer.add(
new Task(Action.valueOf(textinput), Target.APPLICATION)); new Task(Action.valueOf(textinput), Target.APPLICATION));
} catch(IllegalArgumentException e) { } } catch(IllegalArgumentException e) {}
} }
try { try {
Thread.sleep(SLEEP); Thread.sleep(SLEEP);