Meaningless Drivel is fun!*
The moose likes Game Development and the fly likes KeyText to KeyCode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "KeyText to KeyCode" Watch "KeyText to KeyCode" New topic
Author

KeyText to KeyCode

Tim Porritt
Greenhorn

Joined: Jul 22, 2012
Posts: 4
I'm trying to change a string such as "Up", to the integer 38.
So far, i've gotten all the lines from a file and added them to an ArrayList called "controls".

The file that I get the strings from looks like this:



The code that i've tried using to convert it is as follows:



When i try this, the ifs don't work (as in, the strings don't match), and they just return the 0, and i don't know why.

Please help...

PS. I'll find a way to add all keys to the keycode method later on.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8



That isn't the right way to compare two Strings to see if their contents are correct. That just compares to see if they are actually the same String object, which is a different thing entirely. Two different String objects can certainly contain the same data, and that's what is happening here. You should use String's equals() method to see if two Strings contain the same sequence of characters.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: KeyText to KeyCode
 
Similar Threads
Problem with KeyListener
Recursive Problem.
Arrow key commands and paint method in canvas (mac vs pc)
Knight Tour, Does the recursive call get placed inside the if block?
Tournament Tree help