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.showConfirmDia log 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.i n)); //Declare stdin Input
String yearString, valueString; //Define variable yearString, valueString
// Prompt the user to enter the degree in fahrenheit
String fahrenheitString = JOptionPane.showInputDialo g(null,
"Enter a Fahrenheit degree to convert it to Celsius", "Input", JOptionPane.QUESTION_MESSA GE);
// Convert String to Double
double Fahrenheit = Double.parseDouble(fahrenh eitString) ;
// 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.showMessageDia log(null, output, "Output", JOptionPane.INFORMATION_ME SSAGE);
System.exit(0);
</code>
Thanks
<code>
public static void main(String args[]) throws IOException {
BufferedReader stdin = new BufferedReader (new InputStreamReader(System.i
String yearString, valueString; //Define variable yearString, valueString
// Prompt the user to enter the degree in fahrenheit
String fahrenheitString = JOptionPane.showInputDialo
"Enter a Fahrenheit degree to convert it to Celsius", "Input", JOptionPane.QUESTION_MESSA
// Convert String to Double
double Fahrenheit = Double.parseDouble(fahrenh
// 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.showMessageDia
System.exit(0);
</code>
Thanks
ASKER
When I hit 'No', it terminates the loop, instead of re-asking the question.
can you post your loop?
ASKER
I just added the statement you posted at the end of my code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
no worries :)
{
System.exit(0);
}