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

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

View File

@@ -9,27 +9,21 @@ 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() { public void initialise() {
initialise(); input = new Scanner(System.in);
run = true;
new Thread(this).start(); new Thread(this).start();
} }
public void initialise() {
input = new Scanner(System.in);
}
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));