A Callback of this type represents a request to ask the user a yes/no or multiple-choice question. A CallbackHandler should first call getPrompt( ) to obtain the text of the question. It should also call getMessageType( ) to determine the message type (INFORMATION, WARNING, or ERROR) and present the question to the user in a suitable manner based on that type.

Next, the CallbackHandler must determine the appropriate set of responses to the question. It does this by calling getOptionType( ). The return values have the following meanings:


The CallbackHandler should allow the user to respond to the question with a “yes” or a “no” (or their localized equivalents).


The CallbackHandler should allow “yes”, “no”, and “cancel” (or their localized equivalents) responses.


The CallbackHandler should allow “ok” and “cancel” (or their localized equivalents) responses.


The CallbackHandler should call getOptions( ) and use present all strings it returns as possible responses.

In each of these cases, the CallbackHandler should also call getDefaultOption( ) to determine which response should be presented as the default response. If getOptionType( ) returned UNSPECIFIED_TYPE, then getDefaultOption( ) returns an index into the array of options returned by getOptions( ). Otherwise getDefaultOption( ) returns one of the constants YES, NO, OK, or CANCEL.

When the user has selected a response to the ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.