How do I show a message before system.exit in Java -
i trying cover possible options when using joptionpane.showinputdialog box.the user must enter "y" continue running code, "n" cancel procedure , clicking cancel button should same typing "n". but, when user clicks cancel, want show message "you have chosen cancel order" before system.exit(0) runs. have not been able message display. below code have far:
inputstr = joptionpane.showinputdialog("enter order (y/n)"); if(inputstr.equalsignorecase("n")){ joptionpane.showmessagedialog(null, "since not entering order....\n" + "the program close."); system.exit(0); } else if(inputstr.equals(null)){ joptionpane.showmessagedialog(null, "you have chosen cancel order"); system.exit(0); } else if(!inputstr.equalsignorecase("y")){ joptionpane.showmessagedialog(null, "you have entered invalid character.\n" + "enter 'y' or 'n' only."); continue; }
i use yes_no_cancel_option:
object[] options = {"yes","no","cancel"}; int n = joptionpane.showoptiondialog(frame, "continue?", "would continue?", joptionpane.yes_no_cancel_option, joptionpane.question_message, null, options, options[2]); if (n == joptionpane.yes_option) { system.out.println("clicked yes"); } else if (n == joptionpane.no_option) { system.out.println("clicked no"); } else if (n == joptionpane.cancel_option) { system.out.println("clicked cancel"); } else { system.out.println("something else (like clicked 'x' button)"); }
Comments
Post a Comment