• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mouseClicked event for the "Cancel button"

 
Shikha Upadhyaya
Ranch Hand
Posts: 70
Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write the mouseClicked event for the "Cancel button" where the entire window has to close on pressing the Cancel button. I wrote the following code:

But, when I run this code, only the contents of the window get erased and the window remains unclosed. Please let me know what has to be written between lines 104 and 110.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at line 108. You want to close the frame, but all you do is to make the components on your frame invisible. You need to dispose of the frame.

Something like this.


The PmtGui.this is used to tell your anonymous inner class (MouseAdapter) that you are referring to the outer class (PmtGui).

On a side note, don't use MouseListeners on buttons. If you disable the button, the MouseListener will still register events. Rather use an ActionListener.
 
Shikha Upadhyaya
Ranch Hand
Posts: 70
Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riaan Nel wrote:Look at line 108. You want to close the frame, but all you do is to make the components on your frame invisible. You need to dispose of the frame.

Something like this.


The PmtGui.this is used to tell your anonymous inner class (MouseAdapter) that you are referring to the outer class (PmtGui).

On a side note, don't use MouseListeners on buttons. If you disable the button, the MouseListener will still register events. Rather use an ActionListener.

Ok. Thanks It's working now
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic