Link to home
Start Free TrialLog in
Avatar of biloonline
biloonline

asked on

How to implement JOptionPane.showConfirmDialog in my code

This is what I have gotten so far and it debugs with no errors. Now I need to implement the JOptionPane.showConfirmDialog function to prompt the user as to whether 'End program' or not.

<code>
  public static void main(String args[]) throws IOException {
    BufferedReader stdin  = new BufferedReader (new InputStreamReader(System.in));  //Declare stdin  Input
    String yearString, valueString; //Define variable yearString, valueString
    // Prompt the user to enter the degree in fahrenheit
    String fahrenheitString = JOptionPane.showInputDialog(null,
        "Enter a Fahrenheit degree to convert it to Celsius", "Input", JOptionPane.QUESTION_MESSAGE);
    // Convert String to Double
    double Fahrenheit = Double.parseDouble(fahrenheitString);
    // Convert from Fahrenheit to Celsius
    double Celsius = (5.0/9) * (Fahrenheit - 32);
    // Display output
    String output = + Fahrenheit + " degree fahrenheit is equal to " + Celsius + " degree celsius";
    JOptionPane.showMessageDialog(null, output, "Output", JOptionPane.INFORMATION_MESSAGE);

    System.exit(0);
</code>
Thanks
Avatar of Mick Barry
Mick Barry
Flag of Australia image

if (JOptionPane.YES_OPTION==JOptionPane.showConfirmDialog(null, "Do you want to exit?"))
{
   System.exit(0);
}
Avatar of biloonline
biloonline

ASKER

When I hit 'No', it terminates the loop, instead of re-asking the question.
can you post your loop?
I just added the statement you posted at the end of my code.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.
no worries :)