Make a function in outer class where you are implementing the JFrame (you need to close on pressing cancel button).
Write this.setVisible(false); in the implementation of that function.
Finally call this function in the ActionListener implementation when you want to close it.