Recently I just learned Java graphical interface programming and want to write a notebook independently. I want to set a listener for the buttons in the dialog box, but I did not find the corresponding method for viewing the API. I only found this:
Returns:
An integer indicating the option selected by the user
Showconfirmdialog this method returns only one int value to identify which button the user has selected. After searching for half a day, I didn't find the method to set the listener .....
At this moment ..... A flash of light ~~~~
Many methods return 0 in normal cases, and-1 in abnormal cases.
So I tested it with the following code:
After I click yes, the following result is displayed:
Description: The Int value corresponding to the "yes" button in the dialog box is 0.
So do not set the listener. Simply add the code to be completed in IF.
The above is just a humble opinion. If there is a better way to pass by, leave a message ~~!
How to Set a listener for the buttons in the showconfirmdialog dialog box of joptionpane