版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、廣州大學(xué)學(xué)生實(shí)驗(yàn)報(bào)告開(kāi)課學(xué)院及實(shí)驗(yàn)室:計(jì)算機(jī)科學(xué)與工程實(shí)驗(yàn)室2014年12月13日學(xué)院計(jì)算機(jī)科學(xué)與教育軟件學(xué)院年級(jí)/專(zhuān)業(yè)/班姓名學(xué)號(hào)實(shí)驗(yàn)課程名稱(chēng)計(jì)算機(jī)網(wǎng)絡(luò)實(shí)驗(yàn)成績(jī)實(shí)驗(yàn)項(xiàng)目名稱(chēng)網(wǎng)絡(luò)程序設(shè)計(jì)指導(dǎo)老師熊偉1、 程序演示使用蘋(píng)果編程語(yǔ)言實(shí)現(xiàn)程序效果,模擬器運(yùn)行結(jié)果如下:?jiǎn)?dòng)后畫(huà)面單擊C機(jī)單擊C后單擊D,顯示結(jié)果單擊A后單擊C,顯示結(jié)果2、 程序設(shè)計(jì)思路根據(jù)網(wǎng)橋轉(zhuǎn)發(fā)規(guī)則,我首先設(shè)計(jì)了PC類(lèi),代表主機(jī)。Bridege類(lèi),代表網(wǎng)橋,實(shí)例方法包括一些數(shù)據(jù)幀轉(zhuǎn)發(fā),登記移除轉(zhuǎn)發(fā)表等。Framing類(lèi),代表數(shù)據(jù)幀,包括一些屬性:目的地址,源地址等。由于算法并不復(fù)雜,而且基于ios平臺(tái)的開(kāi)發(fā)本來(lái)就比較熟手,開(kāi)發(fā)過(guò)程并
2、沒(méi)遇到什么困難。3、 程序流程圖3、 程序源代碼由于篇幅有限,就不粘貼過(guò)多的代碼。所有源代碼壓縮至附件上傳。下面僅顯示部分代碼。Network類(lèi),構(gòu)建UI畫(huà)面,并負(fù)責(zé)協(xié)調(diào)處理PC,Bridge直接數(shù)據(jù)的傳遞。/ Network.m/ BridgeTransfer/ Created by Jeans on 12/14/14./ Copyright (c) 2014 Jeans. All rights reserved./#import Network.h#import ShapeView.h#import Bridge.h#import PC.h#define AppSize UIScreen
3、mainScreen.applicationFrame.size#define HorizontalSpacing 35#define VerticalSpacing 80#define kAnimationDuring 2interface Network()property (strong, nonatomic) PC *A;property (strong, nonatomic) PC *B;property (strong, nonatomic) PC *C;property (strong, nonatomic) PC *D;property (strong, nonatomic)
4、Bridge *B1;property (strong, nonatomic) ShapeView *pathShapeView;property (strong, nonatomic) ShapeView *backgroundShapeView;property (strong, nonatomic) UILabel *resultLabel;endimplementation Network- (id)initWithFrame:(CGRect)frame if (self = super initWithFrame:frame)/ self.backgroundColor = UICo
5、lor grayColor; /添加對(duì)象 CGPoint pcPoint = CGPointMake(HorizontalSpacing, VerticalSpacing); self.A = self NewPCByOrigin:pcPoint; self.A.name = A; pcPoint.x += HorizontalSpacing + self.A.frame.size.width; self bringSubviewToFront:self.A; self.B = self NewPCByOrigin:pcPoint; self.B.name = B; pcPoint.x +=
6、HorizontalSpacing + self.B.frame.size.width; self.B1 = self NewBridgeByOrigin:CGPointMake(pcPoint.x, 10); pcPoint.x += HorizontalSpacing + self.B1.frame.size.width; self.B1.port1PCs = self.A,self.B; self.C = self NewPCByOrigin:pcPoint; self.C.name = C; pcPoint.x += HorizontalSpacing + self.C.frame.s
7、ize.width; self.D = self NewPCByOrigin:pcPoint; self.D.name = D; pcPoint.x += HorizontalSpacing + self.D.frame.size.width; self.B1.port2PCs = self.C,self.D; /繪制背景線 CGFloat y = self.B1.frame.origin.y + self.B1.frame.size.height - 10; UIBezierPath *path = UIBezierPath bezierPath; path moveToPoint:CGPo
8、intMake(10, y); path addArcWithCenter:CGPointMake(10, y) radius:4.0 startAngle:0 endAngle:2*M_PI clockwise:YES; CGPoint p = CGPointMake(self.B1.frame.origin.x, y); path addLineToPoint:p; p.x += self.B1.frame.size.width; path moveToPoint:p; p.x = self.frame.size.width - 10; path addLineToPoint:p; pat
9、h addArcWithCenter:p radius:4.0 startAngle:0 endAngle:2*M_PI clockwise:YES; p.x = self.A.frame.origin.x+self.A.frame.size.width/2; path moveToPoint:p; path addLineToPoint:CGPointMake(p.x, VerticalSpacing); p.x = self.B.frame.origin.x+self.B.frame.size.width/2; path moveToPoint:p; path addLineToPoint
10、:CGPointMake(p.x, VerticalSpacing); p.x = self.C.frame.origin.x+self.C.frame.size.width/2; path moveToPoint:p; path addLineToPoint:CGPointMake(p.x, VerticalSpacing); p.x = self.D.frame.origin.x+self.D.frame.size.width/2; path moveToPoint:p; path addLineToPoint:CGPointMake(p.x, VerticalSpacing); self
11、.backgroundShapeView.shapeLayer.path = path.CGPath; self drawLineAnimation:self.backgroundShapeView.shapeLayer; return self;- (PC*)NewPCByOrigin:(CGPoint)aOrigin PC *pc = (PC*)NSBundle mainBundleloadNibNamed:PC owner:self options:nillastObject; pc.frame = CGRectMake(aOrigin.x, aOrigin.y, pc.frame.si
12、ze.width, pc.frame.size.height); pc.delegate = self; self addSubview:pc; return pc;- (Bridge*)NewBridgeByOrigin:(CGPoint)aOrigin Bridge *bri = (Bridge*)NSBundle mainBundleloadNibNamed:Bridge owner:self options:nillastObject; bri.frame = CGRectMake(aOrigin.x, aOrigin.y, bri.frame.size.width, bri.fram
13、e.size.height); self addSubview:bri; return bri;- (ShapeView*)backgroundShapeView if (!_backgroundShapeView) _backgroundShapeView = ShapeView allocinit; _backgroundShapeView.shapeLayer.fillColor = nil; _backgroundShapeView.shapeLayer.strokeColor = UIColor colorWithRed:0 green:0 blue:0 alpha:1.CGColo
14、r; _backgroundShapeView.shapeLayer.lineWidth = 1; _backgroundShapeView.shapeLayer.frame = self.bounds; _backgroundShapeView.shapeLayer addSublayer:self.A.layer; _backgroundShapeView.shapeLayer addSublayer:self.B.layer; _backgroundShapeView.shapeLayer addSublayer:self.C.layer; _backgroundShapeView.sh
15、apeLayer addSublayer:self.D.layer; self.layer addSublayer:_backgroundShapeView.shapeLayer; return _backgroundShapeView;- (UILabel*)resultLabel if (!_resultLabel) _resultLabel = UILabel allocinitWithFrame:CGRectMake(self.B1.frame.origin.x+self.B1.frame.size.width/2 - 250,200,500,50); _resultLabel.tex
16、tAlignment = NSTextAlignmentCenter; _resultLabel.backgroundColor = UIColor clearColor; self.backgroundShapeView.shapeLayer addSublayer:_resultLabel.layer; return _resultLabel;#pragma mark - 畫(huà)線-(void)drawLineAnimation:(CALayer*)layer CABasicAnimation *bas = CABasicAnimation animationWithKeyPath:strok
17、eEnd; bas.duration = kAnimationDuring; bas.delegate = self; bas.fromValue = 0.0; bas.toValue = 1.0; layer addAnimation:bas forKey:key;#pragma mark - PC Delegate- (void)PCPressed:(PC *)aPC self.resultLabel.text = self.B1 addOrRemovePC:aPC;endBridge類(lèi),網(wǎng)橋類(lèi),根據(jù)網(wǎng)橋轉(zhuǎn)發(fā)規(guī)則實(shí)現(xiàn)轉(zhuǎn)發(fā)功能,并輸出對(duì)應(yīng)文字提示。/ Bridge.m/ BridgeTran
18、sfer/ Created by Jeans on 12/14/14./ Copyright (c) 2014 Jeans. All rights reserved./#import Bridge.h#import PC.hinterface Bridge()property (strong, nonatomic) NSMutableArray *currentPCs;endimplementation Bridge- (id)initWithCoder:(NSCoder *)aDecoder if (self = super initWithCoder:aDecoder) self cust
19、omInit; return self;- (id)initWithFrame:(CGRect)frame if (self = super initWithFrame:frame) self customInit; return self;- (void)customInit - (NSMutableArray*)currentPCs if (!_currentPCs) _currentPCs = NSMutableArray allocinit; return _currentPCs;- (NSString*)addOrRemovePC:(PC *)aPC NSString *string = nil; if (self.currentPCs containsObject:aPC) self.currentPCs removeObject:aPC; else self.currentPCs addObject:aPC; string = NSString stringWithFormat:%-,aPC.name; if
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度個(gè)人房產(chǎn)買(mǎi)賣(mài)合同(含家具家電及家具安裝)2篇
- 商鋪出租委托代理合同(2025年度)
- 餐飲業(yè)2025年度四人合作經(jīng)營(yíng)合同范本
- 個(gè)人住宅翻新合同簡(jiǎn)要版 2024年適用版B版
- 二零二五年度跨區(qū)域數(shù)據(jù)安全協(xié)議搭建與執(zhí)行合同4篇
- 2025年度出口退稅賬戶(hù)托管業(yè)務(wù)合作合同模板4篇
- 個(gè)性化離婚合同模板:財(cái)產(chǎn)分割與子女撫養(yǎng)權(quán)益保障版B版
- 2025年度智能化煤礦設(shè)備安裝與維護(hù)服務(wù)合同4篇
- 股權(quán)收購(gòu)居間服務(wù)2025年度合同5篇
- 2025年度養(yǎng)老院物業(yè)委托管理與運(yùn)營(yíng)合同4篇
- 油氣行業(yè)人才需求預(yù)測(cè)-洞察分析
- 《數(shù)據(jù)采集技術(shù)》課件-Scrapy 框架的基本操作
- 高一化學(xué)《活潑的金屬單質(zhì)-鈉》分層練習(xí)含答案解析
- 華為集團(tuán)干部管理
- 圖書(shū)館前臺(tái)接待工作總結(jié)
- 衛(wèi)生院藥品管理制度
- 理論力學(xué)智慧樹(shù)知到期末考試答案章節(jié)答案2024年中國(guó)石油大學(xué)(華東)
- 2024老年人靜脈血栓栓塞癥防治中國(guó)專(zhuān)家共識(shí)(完整版)
- 四年級(jí)上冊(cè)脫式計(jì)算100題及答案
- 上海市12校2023-2024學(xué)年高考生物一模試卷含解析
- 儲(chǔ)能電站火災(zāi)應(yīng)急預(yù)案演練
評(píng)論
0/150
提交評(píng)論