Hi Dw

I've created a console application and now I want it to close or teminate straight when I choose exit I've tried the System.Exit(0) but it doesn't close the command screen please help me out. Thanks

Recommended Answers

All 4 Replies

What's the complete sequence of events? Do you open a command window first, then run java - jar ... and want the command window to close when the app finishes?
... in which case maybe a small batch file that runs your app then has an exit command?

Well for now I execute the command manually then after that I type in the jave -jar ... but later I will try to execute this command via a vb program then instruct it to open my project. I want the command window to automatically close when the application is done and here is how I did it I posted with some menu options please refere to the code.

 public void mainMenu(){
        int selection;
        System.out.print("Welcome to the Automated Teller Machine!\n");
        System.out.println("Select from the following menu options below:\n");
        System.out.println("========================");
        System.out.println("| [1]  Check Balance   |");
        System.out.println("| [2]  Withdrawal      |");
        System.out.println("| [3]  Deposit         |");
        System.out.println("| [4]  Exit            |");
        System.out.println("========================");
        System.out.print("Please select your option now: ");
        selection =input.nextInt();

        switch (selection){
    case 1:
        viewBalance();
        break;
    case 2:
        withdrawFunds();
        break;
    case 3:
        depositFunds();
        break;
    case 4:
        System.out.println(" Have a nice day thank you for using this ATM.Bye! \n");
        Runtime.getRuntime();
        System.exit(0); // Here I'm trying to close the cmd when I choose the exit option.
        }
    }

Thank you.

Since the command window was open before the java program started I think it unlikely that the Java program can close it. Hence my previous suggestion of wrapping it ina two-line batch file. However, if you are using VB to manage the startup presumably you can use that to exit the command prompt.

Looking wider, there's no point putting too much effort into this. Nobody actually uses the console for user interaction in real-life Java, and if you are using a real GUI you won't need the command window/console in the first place.

I want to change this to use the pictures as my GUI but the problem is that I think I will have a problem trying to listen or track the side keypad for a real ATM Device so that why I choosed to use the consol because every computer do have a consol application so I will later on try to use the GUI I saw some application project it has some pictures used there but I don't know if when you use it on an ATM if it will be tracked or the buttons will be clicked when let say you press the ATM side buttons which is for optional money choices.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.