Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to implement JOptionPane.showConfirmDialog in my code

Posted on 2004-09-29
7
Medium Priority
?
500 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 200 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

705 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