Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2012-10-16 04:46:40 -0400
committerThomas Schuetz2012-10-16 04:46:40 -0400
commitc14e5c67d91f382633550038d2d5de9fdf6b20b9 (patch)
tree18ad0cd042b5aa954bca52824f0a64476bb0d8d7
parent4414f03679874220a23c1de838238f5bed933bc7 (diff)
downloadorg.eclipse.etrice-c14e5c67d91f382633550038d2d5de9fdf6b20b9.tar.gz
org.eclipse.etrice-c14e5c67d91f382633550038d2d5de9fdf6b20b9.tar.xz
org.eclipse.etrice-c14e5c67d91f382633550038d2d5de9fdf6b20b9.zip
[tutorials.simulators.trafficlight] fixed all warnings, small
refactorings
-rw-r--r--examples/org.eclipse.etrice.tutorials.simulators.trafficlight/release/trafficlight.jarbin8589 -> 9011 bytes
-rw-r--r--examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/PedastrianLightWnd.java26
-rw-r--r--examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight2.java6
-rw-r--r--examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight3.java10
4 files changed, 24 insertions, 18 deletions
diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/release/trafficlight.jar b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/release/trafficlight.jar
index 2d42c2b90..907b301a5 100644
--- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/release/trafficlight.jar
+++ b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/release/trafficlight.jar
Binary files differ
diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/PedastrianLightWnd.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/PedastrianLightWnd.java
index 10c98c2b0..94e3ffbe3 100644
--- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/PedastrianLightWnd.java
+++ b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/PedastrianLightWnd.java
@@ -36,10 +36,6 @@ public class PedastrianLightWnd extends Frame {
Button requestButton = null;
TextField statusLine = null;
- private void resetLights() {
- carLights.setState(4);
- pedLights.setState(2);
- }
public PedastrianLightWnd(int ipPort) {
super("PedestrianLightsGUI");
@@ -85,21 +81,25 @@ public class PedastrianLightWnd extends Frame {
while (true) {
// open and close socket endlessly
try {
- ServerSocket echod = new ServerSocket(ipPort);
+ // open Socket
+ ServerSocket socketServer = new ServerSocket(ipPort);
- Socket socket = echod.accept();
+ // wait blocking for client to connect
+ Socket socket = socketServer.accept();
statusLine.setText("socket connected !");
- BufferedReader in = new BufferedReader(new InputStreamReader(
- socket.getInputStream()));
+ // prepare input and output streams
+ BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
OutputStream out = socket.getOutputStream();
+ // add listener for outgoing command
buttonListener = new ButtonActionListener(out);
requestButton.addActionListener(buttonListener);
requestButton.setEnabled(true);
resetLights();
+ // read blocking until socket is disconnected
String cmd;
while ((cmd = in.readLine()) != null) {
dispatchCommand(requestButton, cmd);
@@ -114,7 +114,8 @@ public class PedastrianLightWnd extends Frame {
// clean up socket
socket.close();
- echod.close();
+ socketServer.close();
+
} catch (IOException e) {
System.err.println(e.toString());
System.exit(1);
@@ -139,7 +140,7 @@ public class PedastrianLightWnd extends Frame {
if (cmd.equals("carLights=off")) {
carLights.setState(carLights.OFF);
}
-
+
// check pedLights
if (cmd.equals("pedLights=red")) {
pedLights.setState(pedLights.RED);
@@ -160,6 +161,11 @@ public class PedastrianLightWnd extends Frame {
}
}
+ private void resetLights() {
+ carLights.setState(carLights.OFF);
+ pedLights.setState(pedLights.OFF);
+ }
+
private GridBagConstraints makeGbc(int x, int y, int width, int height) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x;
diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight2.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight2.java
index 912e9687d..ff3d40fc1 100644
--- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight2.java
+++ b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight2.java
@@ -21,9 +21,9 @@ import java.awt.Graphics;
public class TrafficLight2 extends Canvas {
private static final long serialVersionUID = 1L;
// Traffic light has 4 states
- final static int RED = 0;
- final static int GREEN = 1;
- final static int OFF = 2;
+ public final int RED = 0;
+ public final int GREEN = 1;
+ public final int OFF = 2;
private int state;
diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight3.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight3.java
index 65e6637ad..7e3314b90 100644
--- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight3.java
+++ b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/TrafficLight3.java
@@ -21,11 +21,11 @@ import java.awt.Graphics;
public class TrafficLight3 extends Canvas {
private static final long serialVersionUID = 1L;
// Traffic light has 4 states
- final static int RED = 0;
- final static int YELLOWRED = 1;
- final static int GREEN = 2;
- final static int YELLOW = 3;
- final static int OFF = 4;
+ public final int RED = 0;
+ public final int YELLOWRED = 1;
+ public final int GREEN = 2;
+ public final int YELLOW = 3;
+ public final int OFF = 4;
private int state;

Back to the top