Results 1 to 3 of 3
Thread: Switch Issues
- 06-13-2012, 01:48 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 25
- Rep Power
- 0
Switch Issues
Hello!
I'm having some issues with a switch, or at least I think it's the switch...
Theoretically, after the switch receives a "YES", it should change the state String to "EXPLORE", thus ending the whole chain. But that's not what's happening.Java Code:// STATE is a String, command is a JTextField // This is all inside of an ActionListener, so nothing happens until it gets input. if (STATE.equals("CREATECHAR")){ String name = command.getText(); display.append("\nAre you sure you want your name to be " + command.getText() + "?"); switch (event.getActionCommand().toUpperCase()){ case "YES": case "Y": player.setName(name); display.append("\nWelcome to Generica, " + player.getName() + "!"); STATE = "EXPLORE"; break; case "NO": case "N": display.append("Well what is your name, then?"); break; } }
Output is:
What is your name, Adventurer?
Are you sure you want your name to be John?
Are you sure you want your name to be Yes?
Welcome to Generica, Yes!
Any idea why I'm getting the odd looping?
Thanks in advance!
- 06-13-2012, 02:26 AM #2
Re: Switch Issues
Try debugging the code by adding some printlns to print out the values of the variables used to control the logic flow.Any idea why I'm getting the odd looping?
The print out should show you what the computer is seeing and help you understand why the code is doing what it is doing.If you don't understand my response, don't ignore it, ask a question.
- 06-13-2012, 02:49 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 25
- Rep Power
- 0
Similar Threads
-
Switch
By java4amanda in forum New To JavaReplies: 13Last Post: 03-21-2012, 09:53 AM -
Working with a switch
By überfuzz in forum New To JavaReplies: 2Last Post: 03-12-2011, 12:47 AM -
switch
By dj kourampies in forum New To JavaReplies: 17Last Post: 01-30-2009, 05:32 PM -
switch
By dj kourampies in forum New To JavaReplies: 2Last Post: 01-30-2009, 08:46 AM -
Switch help please!!!!
By soc86 in forum New To JavaReplies: 6Last Post: 11-23-2008, 07:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks