Problem with Java events

0

I developed an application to mark in and out using a biometric reader, the problem is that the reader is activated with the formWindowOpened method, where I call Capture () which is the one with which I identify the Footprint, this method calls itself hoping that an Entry mark is generated, the problem is that I have a Button (Exit), but when I click on it, it does not perform the action that you should, because the system is still running Capture, and I can not Close the application, because it is blocked.

Does anyone have any suggestions on how to fix it? Could it be with Hilos?

    
asked by Ivan 01.08.2016 в 04:19
source

1 answer

1

As I understood Captura() generates an infinite loop on the main thread, so the Salir() method can not be executed. The most optimal way would be to have a thread on Captura() so that it can run in the background and be able to respond to requests on the main thread.

private Thread tCaptura;

private void formWindowOpened(java.awt.event.WindowEvent evt) {

    // Se instancia tCaptura
    if (tCaptura == null) {
        tCaptura = new Thread(new Runnable() {
            public void run() {
                Captura();
            }
        });
    }

    /*
     * Se verifica que tCaptura este libre para poder leer y no crear un
     * thread hasta que se termina de leer el anterior acceso.
     */
    if (!tCaptura.isAlive()) {
        tCaptura.start();
    }
}
    
answered by 02.08.2016 / 13:52
source