欢迎来到天天文库
浏览记录
ID:53312053
大小:364.00 KB
页数:35页
时间:2020-04-03
《利用UML类图设计Java应用程序详解.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、利用UML类图设计Java应用程序详解(一)在第一部分中,我们实现了5个类。在本部分中,我们接着说明如何利用UML类图来设计余下的各个类。为减少篇幅,本部分着重讲解UML类图及应用,对Java实现代码不再详细描述。下载本文全部代码六、CGPoint类CGPoint类说明了如何利用非抽象类扩展抽象类。CGPoint类是CGObject的子类,CGPoint类扩展了CGObject类,CGPoint类没有再它所继承的变量中增加变量,它所声明的方法只有构造函数和要求它实现的抽象方法。其类图如下:Java实现代码为://CGPoi
2、nt.javapublicclassCGPointextendsCGObject{//MethoddeclarationspublicCGPoint(intx,inty,charch){location=newPoint(x,y);drawCharacter=ch;}publicCGPoint(intx,inty){this(x,y,'+');}publicCGPoint(Pointp){this(p.getX(),p.getY(),'+');}publicCGPoint(Pointp,charch){this(p.get
3、X(),p.getY(),ch);}publicvoiddisplay(PrintCGridgrid){grid.setCharAt(drawCharacter,location);}publicvoiddescribe(){System.out.print("CGPoint"+String.valueOf(drawCharacter)+"");System.out.println(location.toString());}}七、CGBox类CGBox类也扩展了CGObject类。CGBox类提供了在网格上显示矩形的附加
4、变量。CGBox类的类图如下:相应的代码为://CGBox.javapublicclassCGBoxextendsCGObject{//VariabledeclarationsprotectedPointlr;//Lowerrightcornerofabox//MethoddeclarationspublicCGBox(PointulCorner,PointlrCorner,charch){location=ulCorner;lr=lrCorner;drawCharacter=ch;}publicCGBox(Pointul
5、Corner,PointlrCorner){this(ulCorner,lrCorner,'#');}publicvoiddisplay(PrintCGridgrid){intwidth=lr.getX()-location.getX()+1;intheight=lr.getY()-location.getY()+1;PointtopRow=newPoint(location);PointbottomRow=newPoint(location.getX(),lr.getY());for(inti=0;i6、){grid.setCharAt(drawCharacter,topRow);grid.setCharAt(drawCharacter,bottomRow);topRow=topRow.add(1,0);bottomRow=bottomRow.add(1,0);}PointleftCol=newPoint(location);PointrightCol=newPoint(lr.getX(),location.getY());for(inti=0;i>height;++i){grid.setCharAt(drawCharac7、ter,leftCol);grid.setCharAt(drawCharacter,rightCol);leftCol=leftCol.add(0,1);rightCol=rightCol.add(0,1);}}publicvoiddescribe(){System.out.print("CGBox"+String.valueOf(drawCharacter)+"");System.out.println(location.toString()+""+lr.toString());}}八、CGText类CGText类是CG8、Object中的第三个子类。其类图与代码分别如下:相应的代码为://CGText.javapublicclassCGTextextendsCGObject{//VariabledeclarationsStringtext;//MethoddeclarationspublicCGText(Pointp,S
6、){grid.setCharAt(drawCharacter,topRow);grid.setCharAt(drawCharacter,bottomRow);topRow=topRow.add(1,0);bottomRow=bottomRow.add(1,0);}PointleftCol=newPoint(location);PointrightCol=newPoint(lr.getX(),location.getY());for(inti=0;i>height;++i){grid.setCharAt(drawCharac
7、ter,leftCol);grid.setCharAt(drawCharacter,rightCol);leftCol=leftCol.add(0,1);rightCol=rightCol.add(0,1);}}publicvoiddescribe(){System.out.print("CGBox"+String.valueOf(drawCharacter)+"");System.out.println(location.toString()+""+lr.toString());}}八、CGText类CGText类是CG
8、Object中的第三个子类。其类图与代码分别如下:相应的代码为://CGText.javapublicclassCGTextextendsCGObject{//VariabledeclarationsStringtext;//MethoddeclarationspublicCGText(Pointp,S
此文档下载收益归作者所有