九、KeyboardInput类
KeyboardInput类扩展了Java API的DataInputStream类,用来提供获取用户键盘输入的一系列常用的简单方法。其类图设计为:

代码为:
import java.lang.System;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.IOException;
//KeyboardInput.java
public class KeyboardInput extends DataInputStream {
public KeyboardInput(InputStream inStream) {
super(inStream);
}
public char getChar() throws IOException {
String line = readLine();
if(line.length()==0) return ' ';
return line.charAt(0);
}
public String getText() throws IOException {
String line = readLine();
return line;
}
public int getInt() throws IOException {
String line = readLine();
Integer i = new Integer(line);
return i.intValue();
}
public Point getPoint() throws IOException {
System.out.print(" x-coordinate: ");
System.out.flush();
int x = getInt();
System.out.print(" y-coordinate: ");
System.out.flush();
int y = getInt();
return new Point(x,y);
}
}
