public class Menu
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
RESPONSE_CANCEL
Value returned from
getYesNoResponse() if user enters other than 'y', 'yes', 'n', or 'no' (localized
appropriately). |
static int |
RESPONSE_NO
Value returned from
getYesNoResponse() if user answers negatively. |
static int |
RESPONSE_YES
Value returned from
getYesNoResponse() if user answers positively. |
| Constructor and Description |
|---|
Menu(java.lang.String label,
java.lang.String header,
java.lang.String exitPrompt,
java.util.List userItems)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
getYesNoResponse(java.lang.String question)
Pose a yes/no question.
|
static int[] |
parseNumberList(java.lang.String tokenString)
Parse a whitespace-, comma-, or semicolon-separated list
of integers.
|
static java.lang.String |
promptForData(java.lang.String prompt)
Utility routine to gather input from
System.in. |
static java.lang.String |
promptForPassword(java.lang.String prompt)
Utility routine to gather input from
System.in. |
int |
run()
Execute this
Menu instance. |
void |
setAllowMultiSelect(boolean allowMultiSelect)
Enable or disable the selection of multiple menu items at once.
|
void |
setLabel(java.lang.String label)
Set the label for this menu.
|
public static final int RESPONSE_CANCEL
getYesNoResponse() if user enters other than 'y', 'yes', 'n', or 'no' (localized
appropriately).public static final int RESPONSE_NO
getYesNoResponse() if user answers negatively.public static final int RESPONSE_YES
getYesNoResponse() if user answers positively.public Menu(java.lang.String label,
java.lang.String header,
java.lang.String exitPrompt,
java.util.List userItems)
label - text displayed over all menu items.header - optional text to be displayed over the menu itemsexitPrompt - optional text for exit item. If null, "Exit" is used.userItems - List of MenuItem instances. A default
"Exit" item is always provided, so there must not be an
"Exit" item in the list.public void setLabel(java.lang.String label)
label - text displayed over all menu items.public void setAllowMultiSelect(boolean allowMultiSelect)
allowMultiSelect - true to allow multiple item selection, false otherwisepublic static java.lang.String promptForData(java.lang.String prompt)
throws java.io.IOException
System.in.prompt - text to display informing the user what to input.java.io.IOException - thrown by underlying System.in InputStream.public static java.lang.String promptForPassword(java.lang.String prompt)
throws java.io.IOException
System.in.
This will attempt to hide the input as it is typed.
prompt - text to display informing the user what to input.java.io.IOException - thrown by underlying System.in InputStream.public static int getYesNoResponse(java.lang.String question)
question - question text (no question mark).public int run()
throws java.io.IOException
Menu instance.MenuItem selected that caused menu to exit. If the built-in
"Exit" item is selected then the index will be equal to the size of the
List passed to the constructor.java.io.IOException - thrown by underlying System.in InputStream.public static int[] parseNumberList(java.lang.String tokenString)
throws java.lang.NumberFormatException
tokenString - String containing list to parse.ints.java.lang.NumberFormatException - thrown if a token in tokenString
isn't a lexically-valid int according to Java rules.