Solved

How to implement JOptionPane.showConfirmDialog in my code

Posted on 2004-09-29
7
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

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

Author Comment

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

Expert Comment

by:objects
ID: 12185103
can you post your loop?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Accepted Solution

by:
objects earned 50 total points
ID: 12185279
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
ID: 12196395
Thank you.
0
 
LVL 92

Expert Comment

by:objects
ID: 12196419
no worries :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
Java: The Public Class Main 4 45
Problem to Alipay 10 67
how to debug htl and js pages 8 53
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

763 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