Small Doubt
Hi,
Please help with this,
After executing a program, i want to ask the user if he wants to continue or he wants to quit, if he wants to continue he has to go back to the main method. if he wants to quit the program will exit. how do i code this??
Thanks in advance.
Rohan.
[301 byte] By [
rohan076] at [2007-11-11 8:16:57]

# 2 Re: Small Doubt
public void exitApp(){
boolean exitLoop;
while(exitLoop=false){
String userRes = JOptionPane.showInputDialog(null,"End program: Type 'Quit'\nReturn to main: Type 'Main'");
if (userRes.equal("Quit")){
exitLoop=true;
System.exit(0);}
else if (userRes.equal("Main")){
exitLoop=true;
main();}
else{
exitLoop=false;}
}
Import the swing package. I have not tested the above method just wrote it out, there may be some bugs, see if you can get it working.
major at 2007-11-11 22:36:58 >

# 3 Re: Small Doubt
public void promptForExit() {
Scanner scanner = new Scanner(System.in);
System.out.print("Would you like to quit the program? (y/n) ");
if (scanner.next().charAt(0) == 'y') {
System.exit(0);
}
}
destin at 2007-11-11 22:37:56 >
