0

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

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by NormR1
0

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.

0

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 by coil: n/a

0

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 by mike_2000_17: Fixed formatting

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.

Edited by NormR1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.