Just write f.setVisible(false) and try adding this actionlistener to the frame itself.Try if u can do that.