A wizard is a tool that asks the user a series of simple questions, in order to achieve a complex goal, such as installing, configuring or using a complex piece of software. Each question is represented by an object which defines the text of the question to be asked, and the type of the response that is expected. Each question also specifies the next question to be asked, which may depend on the answers to any of the questions that have already been asked. All questions belong to an "interview", and the complete set of questions for a wizard may be grouped into one or more different interviews.
By design, questions are simple to write and do not have any dependence on any GUI API: the presentation of the questions of a wizard is left to a separate utility: more than one may be available.
getNext
method may return
null
. This will prevent any tool processing the questions
from moving beyond this question until a valid response has been given.Question name = new StringQuestion(interview, "name") { { setText("what is your name?"); } protected Question getNext() { return age; } }
Questions can conveniently be created as fields within an implementation of {@link com.sun.interview.Interview Interview}.
Interview personal = new Interview("personal") { { setFirstQuestion(name); setTitle("personal questions"); } private Question name = new StringQuestion(this, "name") { ... }; private Question age = new IntQuestion(this, "int") { ... }; private Question sex = new ChoiceQuestion(this, "sex") { ... }; }{@link com.sun.interview.FinalQuestion FinalQuestion} is a special type of question that is used to indicate the end of an interview, and does not provide any response. You may still choose to set some text to be presented to the user, to announce that they have reached the last question.
Question end = new FinalQuestion(interview, "end") { setText("This completes the interview."); };You can invoke one interview from another by using the {@link com.sun.interview.Interview#callInterview callInterview} method, to recursively invoke a sub-interview before continuing to process to the next question in the current interview. The sub-interview will begin at the first question in that interview, and will proceed until an instance of
FinalQuestion
is found, at which point control will revert
to the successor question given to callInterview
.
Question a5 = new ...Question(....) { .... protected Question getNext() { callInterview(subInterview, a6); } }; // this question will be asked after the subInterview has been completed Question a6 = new ....Question(...) { ... };@since 1.0