FileDocCategorySizeDatePackage
Keyboard.javaAPI DocExample10564Wed Apr 25 17:14:42 BST 2001None

Keyboard

public class Keyboard extends Object

Fields Summary
private static boolean
printErrors
private static int
errorCount
private static String
current_token
private static StringTokenizer
reader
private static BufferedReader
in
Constructors Summary
Methods Summary
public static booleanendOfLine()

         return !reader.hasMoreTokens();
      
private static voiderror(java.lang.String str)

         errorCount++;
         if (printErrors) 
            System.out.println (str);
      
public static intgetErrorCount()

   
   //-----------------------------------------------------------------
   //  Returns the current error count.
   //-----------------------------------------------------------------
          
      
         return errorCount;
      
private static java.lang.StringgetNextInputToken(boolean skip)

         final String delimiters = " \t\n\r\f";
         String token = null;
      
         try 
         {
            if (reader == null) 
               reader = new StringTokenizer 
                     (in.readLine(), delimiters, true);
         
            while (token == null || 
                     ((delimiters.indexOf (token) >= 0) && skip))
            {
               while (!reader.hasMoreTokens()) 
                  reader = new StringTokenizer 
                        (in.readLine(), delimiters,true);
            
               token = reader.nextToken();
            }
         }
             catch (Exception exception) 
            {
               token = null;
            }
      
         return token;
      
private static java.lang.StringgetNextToken()

   
   
   //-----------------------------------------------------------------
   //  Gets the next input token assuming it may be on subsequent
   //  input lines.
   //-----------------------------------------------------------------
           
      
         return getNextToken (true);
      
private static java.lang.StringgetNextToken(boolean skip)

         String token;
      
         if (current_token == null)
            token = getNextInputToken (skip);
         else
         {
            token = current_token;
            current_token = null;
         }
      
         return token;
      
public static booleangetPrintErrors()

         return printErrors;
      
public static booleanreadBoolean()

         String token = getNextToken();
         boolean bool;
         try
         {
            if (token.toLowerCase().equals("true")) 
               bool = true;
            else if (token.toLowerCase().equals("false")) 
               bool = false;
            else 
            {
               error ("Error reading boolean data, false value returned.");
               bool = false;
            }
         }
             catch (Exception exception)
            {
               error ("Error reading boolean data, false value returned.");
               bool = false;
            }
         return bool;
      
public static charreadChar()

         String token = getNextToken(false);
         char value;
         try 
         {
            if (token.length() > 1)
            {
               current_token = token.substring (1, token.length());
            } 
            else
               current_token = null;
         
            value = token.charAt (0);
         } 
             catch (Exception exception) 
            {
               error ("Error reading char data, MIN_VALUE value returned.");
               value = Character.MIN_VALUE;
            }
      
         return value;
      
public static doublereadDouble()

         String token = getNextToken();
         double value;
         try 
         {
            value = (new Double(token)).doubleValue();
         } 
             catch (Exception exception) 
            {
               error ("Error reading double data, NaN value returned.");
               value = Double.NaN;
            }
         return value;
      
public static floatreadFloat()

         String token = getNextToken();
         float value;
         try 
         {
            value = (new Float(token)).floatValue();
         } 
             catch (Exception exception) 
            {
               error ("Error reading float data, NaN value returned.");
               value = Float.NaN;
            }
         return value;
      
public static intreadInt()

         String token = getNextToken();
         int value;
         try 
         {
            value = Integer.parseInt (token);
         } 
             catch (Exception exception) 
            {
               error ("Error reading int data, MIN_VALUE value returned.");
               value = Integer.MIN_VALUE;
            }
         return value;
      
public static longreadLong()

         String token = getNextToken();
         long value;
         try 
         {
            value = Long.parseLong (token);
         } 
             catch (Exception exception) 
            {
               error ("Error reading long data, MIN_VALUE value returned.");
               value = Long.MIN_VALUE;
            }
         return value;
      
public static java.lang.StringreadString()

         String str;
      
         try 
         {
            str = getNextToken(false);
            while (! endOfLine())
            {
               str = str + getNextToken(false);
            }
         }
             catch (Exception exception) 
            {
               error ("Error reading String data, null value returned.");
               str = null;
            }
         return str;
      
public static java.lang.StringreadWord()

         String token;
         try 
         {
            token = getNextToken();
         } 
             catch (Exception exception) 
            {
               error ("Error reading String data, null value returned.");
               token = null;
            }
         return token;
      
public static voidresetErrorCount(int count)

         errorCount = 0;
      
public static voidsetPrintErrors(boolean flag)

         printErrors = flag;