Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing Java Frame

 
mike farad
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just curious; what platform are you using, that is imposing this behaviour?
Geoffrey

------------------
Sun Certified Programmer for the Java 2 Platform
 
mike farad
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WE have both Unix and NT. But this problem is noticed on NT
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CNTL-C is used by most OS's to cancel a process. A java application runs as a process on the OS.
 
Scott Cochrane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Scott Cochrane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, just noticed that it is a Jdesktop pane. Not a JFrame. Sorry about that.
Mike
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic