If you are trying to dynamically create the name of a variable inside your running program, you can't. variable names are used by programmers, not the running code.
Whatever you are REALLY trying to do...there is almost for sure a better way.
Never ascribe to malice that which can be adequately explained by stupidity.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
1
as keycode() returns an int, perhaps all you need to do is something like this
and to check
System.out.println(keycode("C"));
System.out.println(KeyEvent.VK_C);
Tim Porritt
Greenhorn
Joined: Jul 22, 2012
Posts: 4
posted
0
What i'm trying to do is get the keycode for a string.
e.g If the string says "a", i want to return the integer for that, which is KeyEvent.VK_A, or 65.
I already found a way to do this, but it's really long and i have to write out every letter of the alphabet 3 times.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
1
you can simplify it a bit
if(i.equals("A") || i.equals("a"))
can be done
if(i.toUpperCase().equals("A"))
or, in my earlier post
return (int)i.charAt(0);
becomes
return (int)i.toUpperCase().charAt(0);
and the test:
System.out.println(keycode("c"));
System.out.println(keycode("C"));
System.out.println(KeyEvent.VK_C);