How can I exit only my routine, and not the entire virtual machine?

I have a Java swing launcher to run another class (with its main method). Each program has a cancel button to exit it.

I use the System.exit(0);cancel button when I click this.

The launcher launches this at actionPerformed:

if (source==carMenuItem) {
    ta.append("Car launched\n");
    TestCar.main(par);

}
if (source==DialogboxMenuItem) {
    ta.append("Dialogbox launched\n");            
    DialogBox.main(par);
}        
if (source==LengthConversionMenuItem) {
    ta.append("LengthConversion launched\n");            
    LengthConversion.main(par);           
}

When I press the cancel button, it also closes my launcher. How can I avoid this situation?

+5
source share
4 answers

System.exit () shuts down the virtual machine, so your source thread is also shutting down, just return from the main () method.

: main() ( ). main().

+2

dispose() System.exit(): -because System.exit() , .

setVisible() false.

+2
+2

System.exit . JVM .

+1

All Articles