Hi
I want to write a loop that will terminate only when the cancel button is hit. I am using a JOptionPane.ConfirmInputDialog(null message1, Title, JOptionPane.OK_CANCEL_OPTION) to display three different messages at a time and the program will terminate once the cancel button has been hit. can someone please help

oochi

Recommended Answers

All 4 Replies

Sure. Post the code you've got so far, and don't forget to use the code tags.
Dont forget: More specific questions will get you more specific answers.

Member Avatar for coil

If you look at the API for JOptionPane, you'll find that it returns a int value once a button is pressed. You'll also find an int that corresponds to the value returned when the Cancel button is pressed. A simple if-statement should do the trick.

Here is the code as requested.

import javax.swing.*;

public class TriangleType
{
    double a;
    double b;
    double c;

 public void CompareSides()
    {
        String JOptionPane.YES_NO_OPTION = new JOptionPane.YES_NO_OPTION();


          a = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the Value of side A:"));
          b = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the Value of side B:"));
          c = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter the Value of side C:"));

        if ((a==b && a!=c)|| (a==c && b!=a) || (c==b && c!=a))

        {    JOptionPane.showConfirmDialog(null, "This is an Isosceles Triangle\n"+"Would you Like to Continue", "Are You getting Excited?", JOptionPane.YES_NO_OPTION);


        } else if ((a==b)&& (c==b))
          { JOptionPane.showConfirmDialog(null, "This is an Equilateral Triangle\n"+"Would you Like to Continue", "Are You getting Excited?", JOptionPane.YES_NO_OPTION);
        }
          else if(a!=b && b!=c && c!=a)
          {  JOptionPane.showConfirmDialog(null, "This is a Scalene Triangle\n"+"Would you Like to Continue", "Are You getting Excited?", JOptionPane.YES_NO_OPTION);
        }


    System.exit(0);

    }

Have you done as coil suggested:

look at the API doc for JOptionPane's method: showConfirmDialog, you'll find that it returns an int value once a button is pressed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.