all groups > vj# > march 2005 >
You're in the

vj#

group:

Java to J# - Enumeration problem


Java to J# - Enumeration problem MattMcSpirit
3/10/2005 1:11:03 PM
vj#:
Hi guys,

Im struggling with figuring out a way to make the following code work:

public class traffic_light implements Runnable {


enum trafficState { Stop, PrepareToGo, Go, PrepareToStop }
public String name = "";

public traffic_light(String name)

{
this.name = name;
}

public trafficState nowState;

public void run () {

nowState = trafficState.Go;

while (true)

{
timer(1000);

switch (nowState)

{
case Stop:
nowState = trafficState.PrepareToGo;
break;

case PrepareToGo:
nowState = trafficState.Go;
break;

case Go:
nowState = trafficState.PrepareToStop;
break;

case PrepareToStop:
nowState = trafficState.Stop;
break;

} // End switch

this.printOut(nowState);

} // End while.

} //End Run

public void printOut (trafficState state) {

System.out.println("The " + name + " traffic lights say " + state);

}

public static void timer (int delay) {
try {
Thread.sleep(delay); //timer sleeps for 1 second
} catch (InterruptedException exception) {
//Does nothing
}
} // End timer.

public static void main (String args[]) {
traffic_light trafficLight = new traffic_light("normal");
trafficLight.run();

} // End main.

} // End TrafficLight

Im just getting 2 errors, both concerning this line:
enum trafficState { Stop, PrepareToGo, Go, PrepareToStop } stating that
there should be an = before the { and ; expected at the end. Im really not
sure how to fix it. Can anyone give any pointers?

Thanks in advance,

Matt
Re: Java to J# - Enumeration problem Bruno Jouhier [MVP]
4/9/2005 12:00:00 AM
Which version of VS are you using: 2003 or 2005?

In VS2003, you cannot define enums in J#, simply because the version of Java
on which J# is based (1.1.4) did not support enums (enum is not a keyword in
the original Java).

Support for enums has been added in VS2005 (Whidbey).

Bruno

[quoted text, click to view]

AddThis Social Bookmark Button