Solved

How to implement JOptionPane.showConfirmDialog in my code

Posted on 2004-09-29
7
441 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:biloonline
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
if (JOptionPane.YES_OPTION==JOptionPane.showConfirmDialog(null, "Do you want to exit?"))
{
   System.exit(0);
}
0
 

Author Comment

by:biloonline
Comment Utility
When I hit 'No', it terminates the loop, instead of re-asking the question.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
can you post your loop?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:biloonline
Comment Utility
I just added the statement you posted at the end of my code.
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
Comment Utility
you need to add a loop, try:

do
{
    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);
}
while (JOptionPane.YES_OPTION=!JOptionPane.showConfirmDialog(null, "Do you want to exit?"));
0
 

Author Comment

by:biloonline
Comment Utility
Thank you.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
no worries :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 81
bunnyEars2 challenge 6 66
powerN  challenge 3 46
How Complex Is This Java Course ? 9 62
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now