Solved

How to implement JOptionPane.showConfirmDialog in my code

Posted on 2004-09-29
7
490 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
Industry Leaders: 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

636 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