How it could be done: If user pushes "escape" button on keyboard, then executes the code as user pushes on the frame's exit button?

So I have something like: 

```
if(e.getKeyCode() == 27) {
    if (true) {
        /..
    } else {
    // Program behaves so, like the exit button in 
        // the frame was pushed
    }
}

```