public GetKeyDialog(JDialog owner, String title, boolean modal) {
            /** call base class constructor */
            setTitle(title);
            setModal(modal);
            /** setup pointer to point to itself */
            me = this;

            /** add keyboard event handler */
            addKeyListener(new KeyAdapter() {
                /**
                 * Handles key pressed events.
                 * @param evt keyboard event
                 */
                public void keyPressed(KeyEvent evt) {
                    /** if it's waiting for a key */
                    if (waitingForKey) {
                        /** get index of key to set */
                        int i = keysBeingSet[0];
                        int j = keysBeingSet[1];
                        /** get the key pressed */
                        int newKey = evt.getKeyCode();
                        /** key used flag */
                        boolean keyUsed = false;
                        /** see if the key is used already or not */
                        for (int p = 0; p < 4; ++p) {
                            for (int k = 0; k < 5; ++k) {
                                /** if key is used already */
                                if (keys[p][k] == newKey) {
                                    /** if it isn't the key being set */
                                    if (!(p == i && j == k))
                                       /** set key used flag to true */
                                       keyUsed = true;
                                }
                                /** if key used flag is true, then exit loop */
                                if (keyUsed) break;
                            }
                            /** if key used flag is true, then exit loop */
                            if (keyUsed) break;
                        }
                        /** if key isn't used */
                        if (!keyUsed) {
                            /** copy new key */
                            keys[i][j] = newKey;
                            /** reset the key field */
                            keyFields[i][j].setText(
                            KeyEvent.getKeyText(keys[i][j]));
                            /** set waiting for key to false */
                            waitingForKey = false;
                            /** destroy the dialog */
                            dispose();
                        }
                        /** if key is used already */
                        else {
                            /** then show an error dialog */
                            /** create the dialog content */
                            JOptionPane pane = new JOptionPane(
                            "Key: [" + KeyEvent.getKeyText(newKey) +
                            "] is used already.  Pick a different key.");
                            /** setup the dialog controls */
                            pane.setOptionType(-JOptionPane.NO_OPTION);
                            pane.setMessageType(JOptionPane.ERROR_MESSAGE);
                            /** create the dialog */
                            JDialog dialog = pane.createDialog(me, "Error");
                            /** set it so user can't resize the dialog */
                            dialog.setResizable(false);
                            /** show the dialog */
                            dialog.show();
                        }
                    }
                }
            });

            /** set the dialog so the user can't resize it */
            setResizable(false);
            /** set dialog size */
            setSize(300, 0);

            int x = owner.getLocation().x + (owner.getSize().width -
            getSize().width) / 2;
            int y = owner.getLocation().y + (owner.getSize().width -
            getSize().height) / 2;
            /** center the dialog relative to the owner */
            setLocation(x, y);

            /** finally show the dialog */
            show();
        }