0
String[] enrollment = {"first Value", "second value"}

int enroll = JOptionPane.showOptionDialog(null,
            "Please select your enrollment:", "Enrollment",
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
            enrollment, enrollment[1]);

How can I get the value from enroll (like first Value) and compare it in a if statement? Since enroll returns an integer variable.

I dont think this question is a duplicate as marked because I am just trying to get the value inside the integer, store it and compare later.

Maddy
  • 2,025
  • 5
  • 26
  • 59

2 Answers2

3

You may have to do something like this in your if/else checking

  if (enroll != JOptionPane.CLOSED_OPTION) {
      System.out.println(enrollment [enroll ]);
    } else {
      System.out.println("No option selected".);
    }
Garry
  • 4,493
  • 3
  • 28
  • 48
  • so this is what I am trying to achieve `if ( first value && somethingElseHere < integer ){` `do something}` how can I store the value inside enroll to compare it with an integer? – Maddy Jul 06 '15 at 05:57
  • So basically enroll stores option from enrolment which can either be `first Value` or `second value`. But since enroll is an integer value, I cannot compare the actual value (that being `first value` or `second value`). Is there a way I can get the actual values from enroll on selecting it from the dialog box. ? I hope that was a bit more clear? – Maddy Jul 06 '15 at 06:09
  • 1
    returned 'enroll' will be the index for the selected option from the two. If enroll is 0 first value is selected if enroll is 1 second value is selected. Thats it. – Garry Jul 06 '15 at 06:10
  • 1
    so this resolves your issue or there is something else? – Garry Jul 06 '15 at 06:55
  • Great...Kindly accept this is an answer if it helped. – Garry Jul 06 '15 at 07:11
0
if (enroll == 0) {    // 0 here is the first thing in the enrolment array
     // do something

}
Maddy
  • 2,025
  • 5
  • 26
  • 59