This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Closing Java Frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Closing Java Frame" Watch "Closing Java Frame" New topic
Author

Closing Java Frame

mike farad
Greenhorn

Joined: Sep 19, 2001
Posts: 8
I have a Java Frame that closes when I press Ctrl-C. I expected it to paste. Please let me know how a warning message should pop up when I press Ctrl-C instead of closing the window suddenly. Thanks
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
The best way I can think of right off the bat is to add a key listener to the JFrame (JFrame.addKeyListener()) that listens for Control-C. When control-C is found, it puts up a warning dialog.
Originally posted by mike farad:
I have a Java Frame that closes when I press Ctrl-C. I expected it to paste. Please let me know how a warning message should pop up when I press Ctrl-C instead of closing the window suddenly. Thanks


There's nothing more dangerous than a resourceful idiot. ---Dilbert
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
Just curious; what platform are you using, that is imposing this behaviour?
Geoffrey

------------------
Sun Certified Programmer for the Java 2 Platform


Sun Certified Programmer for the Java 2 Platform
mike farad
Greenhorn

Joined: Sep 19, 2001
Posts: 8
WE have both Unix and NT. But this problem is noticed on NT
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
CNTL-C is used by most OS's to cancel a process. A java application runs as a process on the OS.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Scott Cochrane
Greenhorn

Joined: Oct 01, 2001
Posts: 5
I have a small simple app using Frame and with the focus on the window CTRL-C does not close the app. (NT workstation)
However if the DOS window in which the application was started has focus and CTRL-C is pressed the application does stop.
(and is it Frame or JFrame that is being used?)
is this any help?


cheers,<br /> <br /> Scott
Scott Cochrane
Greenhorn

Joined: Oct 01, 2001
Posts: 5
Originally posted by Matt Senecal:
The best way I can think of right off the bat is to add a key listener to the JFrame (JFrame.addKeyListener()) that listens for Control-C. When control-C is found, it puts up a warning dialog.

I thought a Frame is really a window and as such would the WindowListener not be more appropriate - I am probably wrong!
sc
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
I use NT all the time and this does not happen (unless at the DOS prompt).
Scott KeyListener is the right one since it is a KeyEvent not a WindowEvent.
mike farad
Greenhorn

Joined: Sep 19, 2001
Posts: 8
I m suprised that the window closing on CTRL-C is not noticed in some cases. My application is a JFrame and the window as well as the DOS prompt are closed when CTRL-C is pressed on either of them. I m looking for a message when some tries to close the JFrame. I guess Key Listener might be the right choice. Thanks for your input.
mike farad
Greenhorn

Joined: Sep 19, 2001
Posts: 8
Sorry, just noticed that it is a Jdesktop pane. Not a JFrame. Sorry about that.
Mike
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Still doesn't close with Ctrl-C with JDesktopPane on NT for me. The only way it closes is with the DOS window having focus.
Maybe you could post your code.
[This message has been edited by Paul Stevens (edited October 02, 2001).]
 
jQuery in Action, 2nd edition
 
subject: Closing Java Frame