Return boolean before time.sleep finish when pressing a JButton in Java : <p>This is my code. I want to return true if the user press the button and false otherwise. The problem that I have is that when the button is press it still waits for the time.sleep to finish and then returns. How can I work around this?</p>

<pre><code>    public boolean popConfirmation(String action) {
        delete = false;
        JFrame frame = new JFrame();
        frame.setLayout(new BorderLayout());
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
        JButton clickmeButton = new JButton("Click Me");
        buttonPanel.add(clickmeButton);
        frame.add(buttonPanel,BorderLayout.SOUTH);

        frame.setSize(popUpWidth, popUpHeight);
        frame.setLocation(popUpX, popUpY);
        frame.setVisible(true);
        frame.setAlwaysOnTop(ALWAYS_ON_TOP);

        clickmeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                delete = true;
                frame.setVisible(false);
                frame.dispose();                    
            }           
        });

        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            logger.error("Error", e);
        }
        frame.setVisible(false);
        frame.dispose();

        return delete;
    }
</code></pre>
