• Register
0 votes
84 views

Problem :

I want to create a message with a Yes or No button. After that a window will appear with a certain message which will depend on if the user clicked Yes or No.

Following is my code:

public class TestJoptionPane {

    public static void main(String[] args){

      //default icon and custom title

        int dialoge = JOptionPane.showConfirmDialog(

            null,

            "Would you like green eggs and ham?",

            "An Inane Question",

            JOptionPane.YES_NO_OPTION);

         if(true){

            JOptionPane.showMessageDialog(null, "HELLO");

        }

        else {

            JOptionPane.showMessageDialog(null, "GOODBYE");

        }

System.exit(0);

    }

}

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

For better understanding please follow below code snippets.

int dialoge = JOptionPane.showConfirmDialog(null, "Yes No Cancel", "YesNoCancel", JOptionPane.YES_NO_CANCEL_OPTION);

    if(dialoge == 0)

        {

        JOptionPane.showConfirmDialog(null, "You pressed YES\n"+"Your pressed value is = "+ dialoge);

        }

    else if(dialoge == 1)

        {

        JOptionPane.showConfirmDialog(null, "You pressed NO\n"+" Your pressed value is = "+ dialoge);

        }

    else if (dialoge == 2)

        {

        JOptionPane.showConfirmDialog(null, "You pressed CANCEL\n"+" Your pressed value is = "+ dialoge);

        }

    else if (dialoge == -1)

        {

        JOptionPane.showConfirmDialog(null, "You pressed X\n"+" Your pressed value is = "+ dialoge);

        }

OR

int dialoge = JOptionPane.showConfirmDialog(null, "Yes No Cancel", "YesNoCancel", JOptionPane.YES_NO_CANCEL_OPTION);

    switch (dialoge) {

        case 0:

            JOptionPane.showConfirmDialog(null, "You pressed YES\n"+" Your pressed value is = "+ dialoge);

            break;

        case 1:

            JOptionPane.showConfirmDialog(null, "You pressed NO\n"+" Your pressed value is = "+ dialoge);

            break;

        case 2:

            JOptionPane.showConfirmDialog(null, "You pressed CANCEL\n"+" Your pressed value is = "+ dialoge);

            break;

        case -1:

            JOptionPane.showConfirmDialog(null, "You pressed X\n"+" Your pressed value is = "+ dialoge);

            break;

        default:

            break;

    }

9 7 4
38,600 points

Related questions

0 votes
1 answer 1 view
1 view
Problem: Please assist me in resolving this issue: which method will return the element that has the id attribute with the specified value
asked Apr 1 rakib1 51.3k points
2 votes
1 answer 23 views
23 views
Problem: I am beginner to jTable. I have already attached the jTable to JDBC database. But I don’t know how to retrieve them. My requirement is the saved data must be shown if I restart my program but currently it is not working for me. I have ... studentName"); String myshool = myrs.getString("schoolName"); String myjoining = myrs.getString("joiningDate"); } Can somebody solve my problem ?
asked Mar 24, 2020 morrisBson 3.2k points
0 votes
1 answer 74 views
74 views
Problem: I am a beginner to java, swing, netbeans and promise. Now I am trying to read and write the Extensible Linking Format (ELF). Please find below the line of code at which I am facing the Error: p = r.exec("./optimizer " + sourceFile + " ... .java:620) at java.lang.Runtime.exec(Runtime.java:450) at java.lang.Runtime.exec(Runtime.java:347) at GUIMode.GUIMode.actionPerformed(GUIMode.java:213)
asked Aug 26, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 2 views
2 views
Problem: Can anyone tell me the solution of this problem? which of the following will load the applet, testapplet?
asked Apr 2 Ifra 24.4k points
0 votes
1 answer 2 views
2 views
Question: I'm trying to write a Swing application in Java that also runs the Google AppEngine Dev-Server and am running into a strange problem with the Swing Eventloop. I have the following two classes: A debug-window, which will eventually receive log ... terminate early (scenario 2 and 3)? Do multi-threaded applications prevent Swing from detecting the last disposed window (scenario 4)?
asked 1 day ago Atik03 4.1k points
0 votes
1 answer 10 views
10 views
Problem: Can anyone tell me the solution of this problem? exception in thread "main" java.lang.unsupportedoperationexception: not supported yet.
asked Mar 25 Ifra 24.4k points
1 vote
1 answer 28 views
28 views
Problem : I am using Netbeans. And Trying to write to an Excel file however I keep getting the error: Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13] Any ideas on what I need to do to fix this? Thanks!
asked Mar 11 Shovo210 13.2k points
0 votes
1 answer 1.1K views
1.1K views
Problem : I want to input some of the details about student to my program. But when I press a save button its giving me the below listed exception error: "Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet."
asked Jan 31, 2020 jwilliam 3.9k points
1 vote
1 answer 39 views
39 views
Problem: I am a beginner level java student. So my question might be very easy for you guys. I am just wondering if it is possible to return multiple values in a single program? If it is possible, can you guys tell me the process, please? -Best regards
asked Mar 9, 2020 Gavin 15.3k points
0 votes
1 answer 1 view
1 view
Problem: can someone please help for this problem? write a program that prompts the user to enter an integer
asked 9 hours ago Rohit kr 15k points