How to terminate program?
<p>How would you make a Java program terminate itself when 'ESCAPE' is pressed? I have tried this:</p>

<pre><code>   public class Main {

   public static final int i = 12;

   public static void Exit(KeyEvent e) {

    if (e.getKeyCode() == 27)
    {
        System.exit(0);
    System.out.println("Closing");
    }

}

public static void main (String args[]) {

    while(i &lt;= 0) {
        Exit(null);
    }

   }
}
</code></pre>

<p>However, it does not appear to work. Any suggestions?</p>
