Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to have multiple option selection in Java?

(I tried to ask a similar question earlier, but couldn't get 100% of what I wanted).

I am writing a program that prompts a user with 5 options, and I would like some way that they can choose to have any number of those options that they want. The program should not continue until the user affirms that it should (with an OK button or something, like JOptionPane) but I want all 5 options visible to the user simultaneously (I was thinking checkboxes, but I don't know how to implement those while still delaying the program until after the user has made their selection. Checkbox implementations I have seen are usually in JFrames and update something immediately as they are checked, not what I want. This occurs in the middle of the method I am writing, not an entire program.)How can I go about doing this?

(Example of such a program that would need this:)

A message appears, the user has 5 options, and can check any number of them. After they hit OK, a message box would appear and tell them the numbers of the boxes they checked. If they checked the first, second, and fourth checkboxes, they would receive a message "1 2 4". I do not want the message to appear until the user has affirmed their final selection.

1 Answer

Relevance
  • Amy
    Lv 7
    6 years ago

    The effect of checking one box is to set an associated variable to "true".

    The effect of clicking the "OK" button is to close the selection pane and move on to the next part of the program.

Still have questions? Get your answers by asking now.