How do I break a while loop if I click on my jframe shutdown? I 'm making a clicker that needs to be stopped at some point, but it'll just continue clicking even tho the exit has been pressed.

```
public class ClickWindow {

private JFrame frame;
private static Clicker click;
private static long currTime;
private static long totalTime;
private JTextField textField;
private static int textFieldValue = 0;
private static Boolean Bool = true;

/**
 * Launch the application.
 */
public static void main(String[] args) throws InterruptedException {

    click = new Clicker();

    ClickWindow window = new ClickWindow();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {

                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public ClickWindow() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setBounds(100, 100, 289, 90);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JButton btnNewButton_1 = new JButton("Press Space");
    btnNewButton_1.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {

            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                Bool = false;
            }

            if (e.getKeyCode() == KeyEvent.VK_SPACE) {

                    if(textFieldValue == 0){
                        textFieldValue = 250;
                    }
                try {

                    while (Bool) {
                        click.click();
                        textFieldValue = Integer.parseInt(textField.getText());
                        Thread.sleep(textFieldValue);
                    }
                } catch (AWTException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (InterruptedException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }
    });
    btnNewButton_1.setBounds(10, 25, 110, 23);
    frame.getContentPane().add(btnNewButton_1);     
    textField = new JTextField();
    textField.setBounds(127, 25, 141, 23);
    frame.getContentPane().add(textField);
    textField.setColumns(10);
}

public void windowClosing(WindowEvent event) {
    Bool = false;
}
}

```

Clicker class

```
public class Clicker{

public static void click() throws AWTException{

    Robot bot = new Robot();        
    bot.mousePress(InputEvent.BUTTON1_MASK);
    bot.mouseRelease(InputEvent.BUTTON1_MASK);
}
}

```

Edited with the full code.