实验8基于事件驱动的程序设计技术.docx
- 文档编号:2184607
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:14
- 大小:684.34KB
实验8基于事件驱动的程序设计技术.docx
《实验8基于事件驱动的程序设计技术.docx》由会员分享,可在线阅读,更多相关《实验8基于事件驱动的程序设计技术.docx(14页珍藏版)》请在冰点文库上搜索。
实验8基于事件驱动的程序设计技术
实验8—基于事件驱动的程序设计技术
实验日期和时间:
实验室:
班级:
学号:
姓名:
实验环境:
1.硬件:
主频:
2.20GHz
内存:
海力士DDR31600MHz2GB
硬盘空间:
500GB5400转/分
操作系统版本:
win7
2.软件:
MicrosoftVisualStudio2010
实验主要任务:
(1)设计一个Windows应用程序,随机生成0~100之间的10个数字,并通过委托实现升序或降序排列。
(2)设计一个Windows应用程序,模拟高温高压锅炉降压处理。
以下内容填写请利用截屏图片和文字对实验原理和实验效果进行说明
任务1()完成情况:
实际效果如下:
代码:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceS8_1
{
publicpartialclassForm1:
Form
{
publicForm1()
{
InitializeComponent();
}
int[]a=newint[10];
delegateboolCompare(intx,inty);
voidSortArray(Comparecompare)
{
for(inti=0;i for(intj=0;j<=i;j++) if(compare(a[i],a[j])) { intt=a[i]; a[i]=a[j]; a[j]=t; } } boolAscending(intx,inty) { returnx } boolDesecding(intx,inty) { returnx>y; } voiddisplay() { textBox2.Text=""; foreach(intiina) { textBox2.Text+=i+"\r\n"; } } privatevoidbutton1_Click(objectsender,EventArgse) { textBox1.Text=""; textBox2.Text=""; Randomr=newRandom(); for(inti=0;i { a[i]=r.Next(100); textBox1.Text+=a[i]+"\r\n"; } } privatevoidbutton2_Click(objectsender,EventArgse) { SortArray(newCompare(Ascending)); display(); } privatevoidbutton3_Click(objectsender,EventArgse) { SortArray(newCompare(Desecding)); display(); } } } 运行结果: 自我评价: 达到了实验预计的效果 任务2()完成情况: 实际效果如下: 代码: usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; namespaceS8_2 { publicpartialclassForm1: Form { publicclassBoilerArgs: EventArgs { privateintpressure; publicBoilerArgs(intn) { pressure=n; } publicintPress { get { returnpressure; } } } publicclassBoiler { publicintk; publicBoiler() { k=0; } publicEventHandler publicvoidProcessAlarm() { this.onAlarm(this,newBoilerArgs(k)); } } privateBoilerboiler; publicForm1() { InitializeComponent(); boiler=newBoiler(); if(boiler.onAlarm==null) boiler.onAlarm+=newEventHandler } privatevoidboiler_Alarm(objectsender,BoilerArgse) { if(e.Press>50&&e.Press<80) { label4.Text="黄色警告! "; label4.BackColor=Color.Yellow; } elseif(e.Press>=80&&e.Press<90) { label4.Text="橙色警告! "; label4.BackColor=Color.Orange; } elseif(e.Press>=90&&e.Press<100) { label4.Text="红色警告! "; label4.BackColor=Color.Red; } elseif(e.Press==100) { label4.Text="已经降压! ......"; label4.BackColor=SystemColors.Control; textBox1.Text="30"; boiler.k=30; } } privatevoidbutton1_Click(objectsender,EventArgse) { timer1.Start(); } privatevoidbutton2_Click(objectsender,EventArgse) { if(Convert.ToInt32(textBox1.Text)>30) { label4.Text="已经降压! ......"; label4.BackColor=SystemColors.Control; textBox1.Text="30"; boiler.k=30; } else { label4.Text="无需降压! ......"; } } privatevoidtimer1_Tick(objectsender,EventArgse) { boiler.k++; textBox1.Text=boiler.k.ToString(); boiler.ProcessAlarm(); } } } 运行结果: 自我评价: 达到了实验预计的效果 总结你在完成任务1-2的过程中遇到的问题及解决的方法: 没有遇到任何问题。 总结本次实验涉及到的基本原理: 基于事件驱动的程序设计技术 本次实验小结: 掌握了委托的声明、实例化和使用方法,了解了多路广播及其应用,还掌握了事件的声明、预定和引用,熟悉了事件数据类的使用方法。 要求: 1.报告格式和内容要求: a.内容和格式整齐。 大标题采用黑体四号字加粗,小标题采用小四号字加粗。 正文采用五号宋体,单倍行距。 b.贴图时请剪裁到适当大小,要保证打印时可以看清,但也不要太大以免“越界”。 c.不要在报告中写与实验无关的话,内容要有条理、完整、并能突出重点,要将遇到的主要问题说明。 2.文件格式要求: a.将实验成果放入一个文件夹中,文件夹的内容包括: 本实验报告、项目。 b.文件夹以“学号姓名_S1”为文件名。 其中,S1表示这是实验1的报告,S大写,以后的实验报告以类似方法编号顺延,注意: 你的学号放在姓名前。 c.注意: 所有文件保存后关闭,然后再打包成RAR文件,以免提交的内容丢失或打不开。 3.提交方式和时间: 一周内完成。 可以将文件包发到我邮箱zcwang@。 4.主动查阅资料,坚持自己亲手完成实验,弄清每个步骤和相关原理。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 基于 事件 驱动 程序设计 技术