I haven't done Java in so long and coming back to it from what seems like years of C++ programming isn't helping any at all.
I'm stuck on enumerations, which are nothing at all like enumerations in C++. When creating an FSM in C++, I could simply use an enumeration to store the states of the machine and in the main loop of the program, I could query the variable that stored the current state and when needed, I could change the state and then accomidate the actions of the program depending upon the value of that variable.
I'm attempting a similar program in Java however I'm running into a lot of problems. For instance, I set up an enumeration with application states like such:
I'm almost positive that's the appropriate way to declare an enumeration.Code:private enum AppStates { STATE_MAIN_MENU, STATE_ADD_ITEM, STATE_ADD_ITEM1, STATE_ADD_ITEM2, STATE_ADD_ITEM3, STATE_APP_STOP }
Next I have a variable to store the application states in so that I can read the current state and change it as needed:
Again, I'm not too sure but I think this is the appropriate declaration for this type of variable.Code:private AppStates CurrentState = AppStates.STATE_MAIN_MENU;
This is where a large deal, in fact all, of my problems are coming from. Inside the main loop I have a while loop controlling the shutdown of the program (visa-vi while AppState isn't in Shutdown State). Then I have a switch structure testing the current value of the variable that holds the application's current state as such:
The compiler keeps complaining about the start of the switch structure saying that it can't make a static reference to a non-static field. I'm seriously drawing blanks here and am going brain dead. Can someone help me out here? Many thanks in advance.Code://Always query the application's state switch(CurrentState) { case AppStates.STATE_MAIN_MENU: //Display the main menu DisplayMainMenu(); break; case AppStates.STATE_ADD_ITEM: //Brings the user to the add item menu DisplayAddItemMenu(); break; case AppStates.STATE_ADD_ITEM1: //Adds an item with no information provided break; case AppStates.STATE_ADD_ITEM2: //Adds an item with only the name and description provided break; case AppStates.STATE_ADD_ITEM3: //Adds an item with everything provided break; case AppStates.STATE_APP_STOP: //This is where the app stops at break; }




Reply With Quote