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

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.

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.

Edited 6 Years Ago by coil: n/a

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);

    }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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.

Edited 6 Years Ago by NormR1: n/a

This article has been dead for over six months. Start a new discussion instead.