HighTechTalks DotNet Forums  

Java to J# - Enumeration problem

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss Java to J# - Enumeration problem in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
MattMcSpirit
 
Posts: n/a

Default Java to J# - Enumeration problem - 03-10-2005 , 04:11 PM






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


Reply With Quote
  #2  
Old   
Bruno Jouhier [MVP]
 
Posts: n/a

Default Re: Java to J# - Enumeration problem - 04-09-2005 , 01:45 PM






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

"MattMcSpirit" <MattMcSpirit (AT) discussions (DOT) microsoft.com> wrote

Quote:
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




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.