Reputation: 3684
I have a gui java program that count the number of files (if any) in a folder and store their names in an array for processing. In the case when no files are available to process, I want to display a joptionpane with the message " No files are available to process. Please click the exit button to exit the system ".
How can I exit the system when the user click the button of the joptionpane? Something like
if (array.length == 0){
JOptionPane.show .......
{
System.exit(0);
}
}
Upvotes: 0
Views: 15164
Reputation: 3684
Thanks David for your help. The following is what I was looking for.
if (filesToCompileArray.length == 0){
int result = JOptionPane.showConfirmDialog(null,
"No failure found in the SUT and no files are generated to process further",
"Confirm Quit", JOptionPane.DEFAULT_OPTION);
if (result == 0) System.exit(0);
}
Upvotes: 0
Reputation: 3656
You can store the return value of the JOptionPane
as such:
int result = JOptionPane.showConfirmDialog(window,
"Are you sure you want to quit?",
"Confirm Quit", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == JOptionPane.YES_OPTION) System.exit(0);
Upvotes: 5