Reputation: 255
I create a simple swing program in which I create a jframe,when we close the jframe it is closed but there is no prompt on cmd,so we use ctrl+c to terminate the program.but when i use the javaw to run the program & close the jframe the prompt is occur on cmd without use of ctrl+c.but i want to know how it is functioning.
Upvotes: 1
Views: 495
Reputation: 33534
java
—the Java application launcher:
The
javaw
command is identical to java, except thatjavaw
has no associated console window. Usejavaw
when you do not want a command prompt window to be displayed. Thejavaw
launcher displays a window with error information if it fails.
Upvotes: 3
Reputation: 17225
javaw.exe is specifically for Windows platform (w stands for windows). If we launch java application using java.exe there is console window associated with it - if you close the console application would also close. javaw.exe is JVM launcher which runs in background without console.
when you close jFrame in java application it does not exits application - you are supposed to capture the window closing event of your application's main windows (jFrame) and exit the application after required cleanup - this behavior is same in java.exe as well as javaw.exe. When you launch the application using java.exe the console shows the application state and you can make out that application is not exiting even if you close the jframe. In case of javaw.exe there is no console - if you close all the windows of GUI application it might be mistaken that application has exited - while the application runs in background as javaw.exe process. To notify users (developers) about this there is a prompt in case of javaw.exe
Upvotes: 0
Reputation: 2124
Try to set the appropriate Closing option for the JFrame Example:
// Create a frame
JFrame frame = new JFrame();
// Get default close operation
int op = frame.getDefaultCloseOperation(); // HIDE_ON_CLOSE
// Set to exit on close
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
you may also overwrite the WindowListener with your own functions called upon the close action, followed by System.exit(0)
Upvotes: 0
Reputation: 32391
Starting your program with javaw will not show the java console, while starting with java will show the java console.
However, I suggest that your program should handle the application exit nicely:
// option 1
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// option 2
frame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// do something here and then
System.exit(0);
}
});
Upvotes: 0
Reputation: 4315
It's specific for Windows. There are 2 types of applications on Windows: console and not. javaw
is a non-console version of java
that is why you don't see console appear. If your application is a graphical one then you should use javaw
.
Upvotes: 0