Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Works on debug mode but not on run mode

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Works on debug mode but not on run mode

    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;
     
             }
    }
    Last edited by JavaPF; April 15th, 2010 at 02:45 AM. Reason: Please use code tags..


Similar Threads

  1. How overloaded paint() works?
    By maikeru in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 21st, 2009, 05:13 PM
  2. How database connection pooling works in a application
    By JayVirk in forum JDBC & Databases
    Replies: 0
    Last Post: October 10th, 2009, 07:14 AM

Tags for this Thread