Dear Java Programmers:
During my life I have programed in several languages all of them compiled or interpreted.
Now I am doing in Java which I use as a type of C, but I have a lot of problems with transporting the code from one machine to another, in fact I am asking for help, because I am working with two machines one foot apart and my code runs perfectly in one but not in the other.
I am at lost on how to solve this problem, as it supposed that the code should run in any machine as my C code works on any machine C compiler.
The details follow:
I have written some small keyboard driven java applications.
They work OK on Eclipse and Netbeans on Centos 4.8 with jdk1.5.0_09.
But, on Centos 5.4 with any Eclipse, Netbeans and java they ignore the key
pressed when they run, but work OK under debug.
I do not know whether it is pertinent but the Centos 4.8 machine has a PS2 keyboard plug and the Centos 5.4 one an usb one.
I know that I was very silly of me to use Java in something in which it
does not have any particular advantage over C, but now it is too late and I need
urgent help, so any clue would be greatly appreciated.
As I said before the code is not the problem as it works in one machine and it is a very usual piece of code, but just in case the pertinent parts of it follow:
The pertinent part of a Canvas class is as follows:
key = new Key(); KeyboardFocusManager manager; manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(key);
In the Canvas I also set the focus, which I do not use, but need for the
next class.
I use the Key class to obtain the characters typed through e:
package system; import java.awt.*; import java.awt.event.KeyEvent; public class Key implements KeyEventDispatcher { KeyEvent e; boolean ready; public Key() { } public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { this.e = e; ready = true; } return true; } public KeyEvent getKey() { while (!ready) { } ready = false; return e; } }