I l@ve RuBoard |
![]() ![]() |
10.5 Getting the ResultsNow that we've seen how to create all sorts of useful dialog boxes, it's time to take a look at how to retrieve information about the user's interaction with the dialog. Table 10-7 showed the return types of the various methods. Here's a quick summary of what the returned values mean.
Getting a value from a JOptionPane you've instantiated directly is also very simple. The value is obtained by calling the pane's getValue( ) method. This method returns an Integer value using the same rules as those described for option dialogs with two small variations. Instead of returning an Integer containing CLOSED_OPTION, getValue( ) returns null if the dialog is closed. Also, if you call getValue( ) before the user has made a selection (or before displaying the dialog at all, for that matter), it will return UNINITIALIZED_VALUE. To get the value of user input (from a JTextField, JComboBox, or JList), call getInputValue( ). This will return the entered String or the selected Object (which may also be a String). Note that, just as with the static "show" methods, there's no way to find out about multiple selections the user may have made when there are more than 20 choices. The following example contains code to retrieve results from JOptionPanes. ![]() |
I l@ve RuBoard |
![]() ![]() |