'JFrame MouseExited

I am starting in Java and my school gave me some homework, that when the mouse leaves the window it closes, the problem is that it closes when I try to hit the buttons.

private void formMouseExited(java.awt.event.MouseEvent evt) {
   System.exit(0);
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source