正 文

利用UML类图设计Java应用程序详解(二)


www.7dspace.com  更新日期:2005-12-12 7:04:29  七度空间


九、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);
}
}

5页,页码:[1] [2] [3] [4] [5] 

上一篇:利用UML类图设计Java应用程序详解
下一篇:当修改final值时要重新编译类
作者:龚赤兵  来源:开发者在线 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐