File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes mouseClicked event for the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "mouseClicked event for the "Cancel button"" Watch "mouseClicked event for the "Cancel button"" New topic
Author

mouseClicked event for the "Cancel button"

Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

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

Joined: Apr 23, 2009
Posts: 157

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.


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mouseClicked event for the "Cancel button"