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
posted
0
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
posted
0
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
posted
0
WE have both Unix and NT. But this problem is noticed on NT
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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).]
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.