TerminalIO
Class KeyboardReader

java.lang.Object
  |
  +--TerminalIO.KeyboardReader

public class KeyboardReader
extends java.lang.Object

The class KeyboardReader contains input methods for terminal I/O. Type-specific methods read characters, integers, doubles, and strings. Another method pauses output and waits for the user to press the enter key to continue. Examples:


   KeyboardReader reader = new KeyboardReader();
   char letter = reader.readChar  ("Enter a letter: ");
   double    d = reader.readDouble("Enter a real number: ");
   int       i = reader.readInt   ("Enter an integer: ");
   String name = reader.readLine  ("Enter your full name: ");
   reader.pause();

 


Constructor Summary
KeyboardReader()
           
 
Method Summary
 void pause()
          Used with non-GUI applications to prevents a "fly-by" disappearance of the terminal window in some environments by pausing execution until the user presses the Enter key.
 char readChar()
          Waits for character input without prompting the user.
 char readChar(java.lang.String prompt)
          Prompts the user and waits for character input.
 double readDouble()
          Waits for double input without prompting the user.
 double readDouble(java.lang.String prompt)
          Prompts the user and waits for double input.
 int readInt()
          Waits for integer input without prompting the user.
 int readInt(java.lang.String prompt)
          Prompts the user and waits for integer input.
 java.lang.String readLine()
          Waits for string input without prompting the user.
 java.lang.String readLine(java.lang.String prompt)
          Prompts the user and waits for string input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyboardReader

public KeyboardReader()
Method Detail

pause

public void pause()
Used with non-GUI applications to prevents a "fly-by" disappearance of the terminal window in some environments by pausing execution until the user presses the Enter key. Usage: reader.pause();

readInt

public int readInt(java.lang.String prompt)
Prompts the user and waits for integer input. Throws an exception if the input doesn't represent an integer. Returns the integer entered.
Parameters:
prompt - the prompt to the user.

readInt

public int readInt()
Waits for integer input without prompting the user. Throws an exception if the input doesn't represent an integer. Returns the integer entered.

readDouble

public double readDouble(java.lang.String prompt)
Prompts the user and waits for double input. Throws an exception if the input doesn't represent a double. Returns the double entered.
Parameters:
prompt - the prompt to the user.

readDouble

public double readDouble()
Waits for double input without prompting the user. Throws an exception if the input doesn't represent a double. Returns the double entered.

readChar

public char readChar(java.lang.String prompt)
Prompts the user and waits for character input. Returns the char entered.
Parameters:
prompt - the prompt to the user.

readChar

public char readChar()
Waits for character input without prompting the user. Returns the char entered.

readLine

public java.lang.String readLine(java.lang.String prompt)
Prompts the user and waits for string input. Returns the entire line of text entered.
Parameters:
prompt - the prompt to the user.

readLine

public java.lang.String readLine()
Waits for string input without prompting the user. Returns the entire line of text entered.