i18n - help

i'm internationalizing an application and don't wanna hardcode anything into the app code, so i'd like to externalize even the keycodes used in the buttons mnemonics. Ok, an example: we've got a button named "Run" in the English props file and "Ejecutar" in the Spanish one. So here's my code right now

if(app_lan.equals("en"))

button.setMnemonic(KeyEvent.VK_R);//Run

if(app_lan.equals("es"))

button.setMnemonic(KeyEvent.VK_E);//Ejecutar

however, when i externalize the keyevents, the english/spanish properties file will return it to me as a string: "KeyEvent.VK_R", "KeyEvent.VK_E".

so the question is, what have i to do with those strings to get the KeyEvent's and invoke the method mnemonic with them? I've tried with Class.forName, with ObjectName... nothing seem to work. somebody any clue for me?

thanks!

[867 byte] By [emra] at [2007-11-27 0:50:06]
# 1

Here is something I did for MenuItems and could be applied for other things. "key" is a String such as "VK_R"

private void assignKeyEvent(JMenuItem mi, String key) {

try {

Field b = KeyEvent.class.getField(key);

mi.setMnemonic(b.getInt(null));

} catch (NoSuchFieldException nsfe) {

System.err.println(nsfe.getMessage());

} catch (IllegalAccessException iae) {

System.err.println(iae.getMessage());

}

}

Edit:

You also, of course, have to

import java.lang.reflect.Field;

masijade.a at 2007-7-11 23:19:59 > top of Java-index,Java Essentials,Java Programming...
# 2
works, it's simple, perfect, thanks :)
emra at 2007-7-11 23:20:00 > top of Java-index,Java Essentials,Java Programming...
# 3
You're Welcome.I have no idea if that is the best, or even a good, way of doing it, but it came to me in flash after a long night one time, and it worked, so I kept it.
masijade.a at 2007-7-11 23:20:00 > top of Java-index,Java Essentials,Java Programming...