How to Set a listener for the buttons in the showconfirmdialog dialog box of joptionpane

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.