List of utility methods to do Console Prompt
String | prompt(String message) Prompts the user with a given message and returns their response. System.out.print(message + ": "); return scan.nextLine(); |
String | prompt(String message, String defaults) Prompt user for input, providing a default input. System.out.print(message + " [" + defaults + "]: "); String line = in.nextLine().trim(); return line.equals("") ? defaults : line; |
String | prompt(String output) prompt System.out.print(output); Scanner input = new Scanner(System.in, "utf-8"); String line = input.nextLine(); input.close(); return line; |
String | prompt(String prompt) Shorthand for the scanner creation, the posing of the question, and the getting of the response. System.out.print(prompt + "\t"); return scan.nextLine(); |
void | promptEnterKey() Pause execution and allow the user to continue by pressing ENTER. System.out.println("An Event has occured! Press \"ENTER\" to continue...");
scanner.nextLine();
|
String | promptHidden(String message) Prompot user for input, hiding the input if possible. if (System.console() != null) { System.out.print(message + ": "); char[] line = System.console().readPassword(); return new String(line); return prompt(message); |
void | promptPressEnterToExit() Prompts the user to press the enter key to exit the JVM process. System.err.println("Press <enter> to exit..."); new Scanner(System.in).nextLine(); |
String | promptRequired(String message) Prompt user for input, requiring non-empty input. System.out.print(message + ": "); String line = in.nextLine().trim(); return line.equals("") ? promptRequired(message) : line; |