How to capture "CTRL C" in a java program
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anand_S
Posted On:   Monday, June 11, 2001 01:15 AM

When an application is running, if the user presses "CTRL C" the application will exit. So I dont want to exit my application I have to trap the "CTRL C" so that when the user presses "CTRL C" then i have to perform some other functionality.

- Thans in advance...

Re: How to capture "CTRL C" in a java program

Posted By:   Simon_Ablett  
Posted On:   Thursday, June 28, 2001 07:16 AM

If you're writing java to run on various platforms. Bear in mind that CTRL-C might not mean the same on all of them.

Re: How to capture "CTRL C" in a java program

Posted By:   Luigi_Viggiano  
Posted On:   Monday, June 11, 2001 04:31 AM

This is how to catch CTRL-C to free up resources before exit:


import java.io.IOException;
public class CtrlC extends Thread {

public CtrlC() {
Runtime.getRuntime().addShutdownHook(this);
}

public void run() {
System.out.println("CTRL-C catched! ");
}

public static void main(String[] args) {
new CtrlC();
System.out.println("Press CTRL-C");
while (true)
try {
System.in.read();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

Re: How to capture "CTRL C" in a java program

Posted By:   Anonymous  
Posted On:   Monday, June 11, 2001 02:07 AM

Hi,


Check this info...
The javaw command is identical to java, except that with javaw there is no
associated console window. Use javaw when you don't want a command
prompt window to appear. The javaw launcher will, however, display a
dialog box with error information if a launch fails for some reason.
About | Sitemap | Contact