Salve a tutti,
ho un problemino con un KeyListener..

Ho creato un JOptionPane personalizzato (ci ho inserito una JLabel, una JPasswordField, etc) che richiede in input una stringa e controlla che questa stringa sia identica a quella già memorizzata.
Il metodo si chiama loopTheUserInputWindow() e restituisce un valore "int".

- se Stringa1==Stringa2, restituisco 0
- se Stringa1 != Stringa2, restituisco -1
- altrimenti restituisco 1 (nel caso in cui l'utente chiuda il pannello)

Questo funziona benissimo finché l'utente, dopo aver inserito la stringa, clicca sul tasto "OK" del JOptionPane.
Io però vorrei anche implementare la possibilità di andare avanti cliccando ENTER sulla tastiera, per cui ho aggiunto un KeyListener alla JPasswordField (sono sempre all'interno del metodo loopTheUserInputWindow() ).
Il problema é che, dall'interno del metodo eriditato keyPressed() non posso restituire un valore di tipo "int", perché questo metodo keyPressed é definito come "VOID".

Il codice é in basso..qualcuno potrebbe aiutarmi ?

codice:
private int loopTheUserInputWindow(){             

                /*** CREATING THE INPUT BOX TO REQUEST THE PASSWORD ***/

        Object[] messageInTheBox= {"Please enter your password",usersPasswordField};
        String cryptoPopUPTitle="Authentication Required";
        Object[] usersOptions= {"OK","CANCEL"};     

                /* CREATE PASSWORD FIELD TO BE PUT LATER ON IN THE USER DIALOG BOX */

                usersPasswordField.setText(""); // RESET THE FIELD
                usersPasswordField.setEchoChar('*');                                       usersPasswordField.setColumns(14);                          // MAX LENGHT --> 14 characters

        usersPasswordField.addKeyListener(new KeyListener(){                    
                // QUI C'É IL KEY LISTENER CHE VORREI IMPLEMENTARE
                public void keyTyped(KeyEvent e) {}
                public void keyReleased(KeyEvent e) {}
                public void keyPressed(KeyEvent e) {
                     // QUI DOVREI FARE IL CONTROLLO E RESTITUIRE UN int 
                     // AL METODO loopTheUserInputWindow..

                }

        });

        if (JOptionPane.showOptionDialog(index, messageInTheBox, cryptoPopUPTitle,

                                JOptionPane.YES_NO_OPTION, 0, new ImageIcon("images\\crypto_icon_small.JPG"), usersOptions, 

                                messageInTheBox) == JOptionPane.YES_OPTION)

                        // USER CLICKED THE YES BUTTON 

                {       

                if (continueWithPassword(new String(usersPasswordField.getPassword())))
                        // RIGHT PASSWORD !!!
                        return 0;
                else {
                        // WRONG PASSWORD !!!
                        return -1;
                }
                }                       
        else {
                   // USER CLICKED "NO" BUTTON OR CLOSED THE POP-UP WINDOW
                return 1;
        }               
        }