Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2012-06-16 12:18:44 +0000
committerThomas Schuetz2012-06-16 12:18:44 +0000
commit9d2312ca0a58ec9bc7b5f06e5e05866c3a4fc0a4 (patch)
tree0f56139564ce99c949dd13082417d01249ad2cfe
parent56075d7da3b76d7375dcceed4dcb4d604fa3d807 (diff)
downloadorg.eclipse.etrice-9d2312ca0a58ec9bc7b5f06e5e05866c3a4fc0a4.tar.gz
org.eclipse.etrice-9d2312ca0a58ec9bc7b5f06e5e05866c3a4fc0a4.tar.xz
org.eclipse.etrice-9d2312ca0a58ec9bc7b5f06e5e05866c3a4fc0a4.zip
[tutorials.simulators.trafficlight] added command line argument for ip-port, check and usage message for commandline
-rw-r--r--examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/Main.java32
-rw-r--r--examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/PedastrianLightWnd.java6
2 files changed, 33 insertions, 5 deletions
diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/Main.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/Main.java
index 8f90361da..33693c833 100644
--- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/Main.java
+++ b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight/src/org/eclipse/etrice/tutorials/simulators/trafficlight/Main.java
@@ -6,8 +6,36 @@ public class Main {
* @param args
*/
public static void main(String[] args) {
- // TODO Auto-generated method stub
- PedastrianLightWnd wnd = new PedastrianLightWnd();
+
+ if (checkArgs(args) == false) {
+ System.exit(0);
+ }
+
+ PedastrianLightWnd wnd = new PedastrianLightWnd(Integer.parseInt(args[0]));
+ }
+
+ public static boolean checkArgs(String[] args) {
+ // check length
+ if (args.length != 1) {
+ System.out
+ .println("ERROR: wrong number of arguments - expected 1 argument");
+ printUsage();
+ return false;
+ } else {
+ try {
+ Integer.parseInt(args[0]);
+ return true;
+ } catch (Exception e) {
+ System.out.println("ERROR: integer value expected as argument");
+ printUsage();
+ return false;
+ }
+ }
+ }
+
+ public static void printUsage() {
+ System.out.println("Usage: java -jar trafficlight.jar [ip-address]");
+ System.out.println("Example: java -jar trafficlight.jar 4440");
}
}
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 9e9a13940..372086b2b 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
@@ -10,7 +10,7 @@ import java.awt.event.ActionEvent;
public class PedastrianLightWnd extends Frame {
// Konstructor
- public PedastrianLightWnd (){
+ public PedastrianLightWnd (int ipPort){
super("PedestrianLightsGUI");
GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc;
@@ -33,7 +33,7 @@ public class PedastrianLightWnd extends Frame {
layout.setConstraints(pedLights,gbc);
add(pedLights);
- statusLine.setText("listening on TCP Port 4444");
+ statusLine.setText("listening on TCP Port " + ipPort);
statusLine.setEditable(false);
statusLine.setFocusable(false);
gbc = makeGbc(0,0,2,1);
@@ -51,7 +51,7 @@ public class PedastrianLightWnd extends Frame {
// open socket
try {
- ServerSocket echod = new ServerSocket(4444);
+ ServerSocket echod = new ServerSocket(ipPort);
Socket socket = echod.accept();
statusLine.setText("connected !");

Back to the top