0

i want to disable the NO and CANCEL option , can you guys help me because im only a begineer of JOPTION here is ma code: btw this is my assignment in my 1st year college "compro" my teacher tell us to create a program , and my system is QUESTION and ANSWER my problem is there was a NO and CANEL option what if the teacher click it then the null will appear , (all i need is, if the teacher click the NO or CANCEL the program will exit .)

import javax.swing.*;
import java.io.*;
public class QA
{
    public static void main(String[]args)throws IOException{

    DataInputStream m = new DataInputStream(System.in);

        JFrame frame = new JFrame("Message");

    JOptionPane.showMessageDialog(frame,
        "WELCOME TO THE WORLD OF JAVA");

    String name= JOptionPane.showInputDialog
    ("Enter your Full Name");

    JOptionPane.showConfirmDialog(null, 
    "Are you Ready"+name, "Choose answer", JOptionPane.YES_NO_OPTION);

        Object[] possibleValues = { "Select answer below","__________",
        "computer", "hardware", "software", "jboy", "rommel", "warren"};
        Object selectedValue = JOptionPane.showInputDialog(null,    
        "It is an electronical device capable of performing complex computations is a short time?", 
        "QUESTION 1",JOptionPane.INFORMATION_MESSAGE, null,possibleValues, possibleValues[0]);

        String choice = selectedValue.toString();
        String answer = "computer";

        if (choice.equals(answer)){

            Object[] options = { "OK", "CANCEL" };
            JOptionPane.showOptionDialog(null, "Your Answer is Correct", "Congrats", 
            JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
            null, options, options[0]);

        }else{

            JOptionPane.showMessageDialog(null, "Your answer is wrong", "Owh-owh", JOptionPane.ERROR_MESSAGE); 

        }

        JFrame frames = new JFrame("Message");

        // show a joptionpane dialog using showMessageDialog
         JOptionPane.showMessageDialog(frame,
        "Click OK to proceed for next question");

        Object[] possibleValues1 = { "Select answer below","__________",
        "rommel", "warren", "jboy" };
        Object selectedValue1 = JOptionPane.showInputDialog(null,   
        "WHO'S LOOK A LIKE OF MR.BEAN?", 
        "QUESTION 2",JOptionPane.INFORMATION_MESSAGE, null,possibleValues, possibleValues[0]);

        String choices = selectedValue.toString();
        String answers = "jboy";

        if (choice.equals(answer)){

            Object[] options = { "OK", "CANCEL" };
            JOptionPane.showOptionDialog(null, "Your Answer is Correct", "Congrats", 
            JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
            null, options, options[0]);

        }else{

            JOptionPane.showMessageDialog(null, "Your answer is wrong", "Owh-owh", JOptionPane.ERROR_MESSAGE); 

        }



         System.exit(0);











    }
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by cale.macdonald
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.