Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / April 2005

Tip: Looking for answers? Try searching our database.

Java to J# - Enumeration problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MattMcSpirit - 10 Mar 2005 21:11 GMT
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
Bruno Jouhier [MVP] - 09 Apr 2005 18:45 GMT
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

> Hi guys,
>
[quoted text clipped - 80 lines]
>
> Matt

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.