首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

小弟我想通过面向对象的方法实现绘制不同的图形,目前小弟我先写了一个绘制直线的类,请朋友指点一下写的对不对,多谢

2011-12-18 
我想通过面向对象的方法实现绘制不同的图形,目前我先写了一个绘制直线的类,请朋友指点一下写的对不对,谢谢

我想通过面向对象的方法实现绘制不同的图形,目前我先写了一个绘制直线的类,请朋友指点一下写的对不对,谢谢!
public   abstract   class   Shape
        {
                public   abstract   void   drawShape(Graphics   graphic,Pen   pen);
                public   Point   firstPoint;
                public   Point   lastPoint;
        }

        public   class   Line   :   Shape
        {
                public   Point   firstPoint;
                public   Point   lastPoint;
                public   override   void   drawShape(Graphics   graphic,Pen   pen)
                {
                        //throw   new   Exception( "The   method   or   operation   is   not   implemented. ");
                        Graphics   g   =   graphic;
                        g.DrawLine(pen,   firstPoint,   lastPoint);
                }
        }

        public   class   DrawShape
        {
                public   DrawShape()
                {
                       
                }
                public   static   Shape   getShape(string   strShape)
                {
                        switch   (strShape)
                        {
                                case   "Line ":
                                        Line   line   =   new   Line();
                                        return   line;

                                default:
                                        return   null;
                        }
                }
        }

[解决办法]
public static Shape getShape(string strShape)
{
switch (strShape)
{


case "Line ":
Line line = new Line();
return line;
case ...
case
case
too long

default:
return null;
}
}

热点排行