您的位置:首页 > 其它

一个组合类问题,对象添加不上,错误!,忘高手探讨!!

2011-04-27 11:20 459 查看

我是想 做一个线路动态的例子,线路动态包括全市区的线路line_f ,每一条具体线路 line_c 和单独线段line



1. Line 基本线段类
2. Line_c 线段集合类 (也称线树类)
3. line_f 全部线段类(也称线段群类)

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

一 线段类
namespace BUS_S
{
#region
/// <summary> line
/// class line
/// </summary>

public class line
{

public int x1;
public int y1;
public int x2;
public int y2;
public int weight;
public int Win32Color;
public string lineid;//

public line( string name)

{
lineid = name;//线段的编号
}

public line(int Win32Color, int x1, int y1, int x2, int y2)
{

this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.Win32Color = Win32Color;

}

public void draw(Graphics g)
{
g.DrawLine(new Pen(ColorTranslator.FromWin32(Win32Color)), x1, y1, x2, y2);
}
}

#endregion

}

二 线段集合
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;

namespace BUS_S
{
public class line_c
{
public ArrayList linesG;//线段组
public string linename;

public line_c ()
{
linesG = new ArrayList();//所有的线段组

}

public line_c(string name)
{
linename = name;
linesG = new ArrayList();//所有的线段组

}

public void clear()
{
linesG.Clear();
}

public void removelastline()
{
int s = linesG.Count;
if (s >= 0)
{
linesG.RemoveAt(s - 1);
}
}

public void add(line l)
{
linesG.Add(l);
}

public void draw(Graphics g)
{

foreach (line l in linesG) //按照线在集合中的顺序依次画出,采用基类的方法
{
l.draw(g);

}

}

}
}

三 全部线段类
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;

namespace BUS_S
{
public class line_f
{
public List<line_c> LineQun;
public string lineForest_name ;//线路的名字
public string clor;
public line_f()
{
List<line_c> LineQun = new List<line_c>();

}

public line_f(string name)
{
lineForest_name = name;
List<line_c> LineQun = new List<line_c>();
}
public void clear()
{
LineQun.Clear();
}

public void removeLine_C()
{
int s = LineQun.Count;
if (s >=0)
{
LineQun.RemoveAt(s - 1);
}
}

/// <summary>
///
/// </summary>
/// <param name="l"></param>
public void add(line_c l)
{
//MessageBox.Show("传递过来的参数"+l.);
LineQun.Add(l);
}

public void draw(Graphics g)
{

foreach (line_c l in LineQun)
{
l.draw(g);

}

}
}
}

四 调用,想在 全部线对象中加入一个线树的对象。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BUS_S
{
public partial class Form1 : Form
{
private line_f linesQunObj = new line_f("线的群");//群的实例
// private line_c linescPointer;//定义类型,在后面指向对象
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
line_c linecObj = new line_c("我是一个线树");
linesQunObj.add(linecObj);
}
}
}

然而出现错误!!



跟踪结果:


为什么上面的lineQun加不上啊 !!!!!
它是空的正常 啊 !因为刚创建就是空的啊!!

lixinhai@163.com 联系我 我惨极了,链条网线也没有!自己好不容易在网吧发的!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐