读书人

小弟我想通过面向对象的方法实现绘制不

发布时间: 2011-12-18 22:54:38 作者: rapoo

我想通过面向对象的方法实现绘制不同的图形,目前我先写了一个绘制直线的类,请朋友指点一下写的对不对,谢谢!
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;
}
}

读书人网 >C#

热点推荐