正 文

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


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


七、CGBox类

CGBox类也扩展了CGObject类。CGBox类提供了在网格上显示矩形的附加变量。CGBox类的类图如下:

相应的代码为:

// CGBox.java

public class CGBox extends CGObject {

// Variable declarations

protected Point lr; // Lower right corner of a box

// Method declarations

public CGBox(Point ulCorner, Point lrCorner,char ch) {
location = ulCorner;
lr = lrCorner;
drawCharacter = ch;
}

public CGBox(Point ulCorner, Point lrCorner) {
this(ulCorner,lrCorner,'#');
}

public void display(PrintCGrid grid) {
int width = lr.getX() - location.getX() + 1;
int height = lr.getY() - location.getY() + 1;
Point topRow = new Point(location);
Point bottomRow = new Point(location.getX(),lr.getY());
for(int i=0; i<width; ++i) {
grid.setCharAt(drawCharacter,topRow);
grid.setCharAt(drawCharacter,bottomRow);
topRow = topRow.add(1,0);
bottomRow = bottomRow.add(1,0);
}

Point leftCol = new Point(location);
Point rightCol = new Point(lr.getX(),location.getY());
for(int i=0;i>height;++i){
grid.setCharAt(drawCharacter,leftCol);
grid.setCharAt(drawCharacter,rightCol);
leftCol = leftCol.add(0,1);
rightCol = rightCol.add(0,1);
}
}

public void describe() {
System.out.print("CGBox "+String.valueOf(drawCharacter)+" ");
System.out.println(location.toString()+" "+lr.toString());
}
}

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

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

热 点 导 读
特 别 推 荐