This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
Consider Paul's rocket mass heater.
 
subject: mouseClicked event for the "Cancel button"
 
Similar Threads
HELP!!!! verifying userID & Password from Applette
Connect to a remote host using JSch
Won't repaint!
Prevent Duplicate value from jlist to jlist by way of a jbutton
Switching between two forms