45fan.com - 路饭网
首页
路由器设置
无线路由器
路由器密码
网络频道
手机频道
电脑频道
图库频道
问答中心
搜索:
智能搜索
搜索标题
您的位置
:
主页
>
电脑频道
>
电脑教程
> 阅读资讯:模拟停止等待协议内容解说
模拟停止等待协议内容解说
2016-09-03 21:24:30 来源:www.45fan.com 【
大
中
小
】
模拟停止等待协议内容解说
package
web;
import
java.awt.Color;
import
java.awt.FileDialog;
import
java.awt.TextArea;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import
java.awt.event.KeyAdapter;
import
java.awt.event.KeyEvent;
import
java.awt.event.KeyListener;
import
java.awt.event.WindowAdapter;
import
java.awt.event.WindowEvent;
import
javax.swing.JButton;
import
javax.swing.JFrame;
//
importjavax.swing.JList;
import
javax.swing.JPanel;
import
javax.swing.JLabel;
import
sun.security.krb5.internal.s;
import
java.awt.List;
import
java.io.BufferedReader;
import
java.io.File;
import
java.io.FileInputStream;
import
java.io.FileNotFoundException;
import
java.io.FileReader;
import
java.io.IOException;
import
java.io.InputStream;
import
java.io.InputStreamReader;
import
java.io.Reader;
import
java.net.
*
;
import
java.util.Random;
public
class
Stop_and_Wait
extends
JFrame
...
{
private
JPaneljPanel;
private
TextAreasentTextArea;
private
JButtonchooseFileButton,sentButton,cleanButton;
private
JLabelsentFileLabel,sentMessageLabel,sentStatusLabel,
receiveStatusLabel,receiveFileLabel;
private
ListsentStatusList,sentAllFileList,receiveStatusList,
receiveFileList;
private
boolean
isTout
=
false
,isACK
=
true
,sentNum
=
true
,
receiveNum
=
false
,changeTemp
=
true
,lastIsACK
=
true
;
private
int
reSentNum
=
0
,lineNum
=
-
1
;
public
Stop_and_Wait()
...
{
init();
listener();
}
public
void
init()
...
{
jPanel
=
new
JPanel();
jPanel.setBackground(Color.PINK);
this
.setContentPane(jPanel);
sentFileLabel
=
new
JLabel(
"
SentFile:
"
);
sentFileLabel.setBounds(
20
,
20
,
100
,
30
);
jPanel.add(sentFileLabel);
sentMessageLabel
=
new
JLabel(
"
AllSentFileMessage:
"
);
sentMessageLabel.setBounds(
20
,
260
,
150
,
30
);
jPanel.add(sentMessageLabel);
sentTextArea
=
new
TextArea();
sentTextArea.setBounds(
20
,
50
,
300
,
200
);
jPanel.add(sentTextArea);
sentAllFileList
=
new
List();
sentAllFileList.setBounds(
20
,
290
,
300
,
200
);
jPanel.add(sentAllFileList);
sentStatusList
=
new
List();
sentStatusList.setBounds(
360
,
50
,
300
,
200
);
jPanel.add(sentStatusList);
receiveFileList
=
new
List();
receiveFileList.setBounds(
690
,
50
,
180
,
440
);
jPanel.add(receiveFileList);
sentStatusLabel
=
new
JLabel(
"
SentStatusMessage:
"
);
sentStatusLabel.setBounds(
360
,
20
,
150
,
30
);
jPanel.add(sentStatusLabel);
receiveFileLabel
=
new
JLabel(
"
ReceiveFile:
"
);
receiveFileLabel.setBounds(
690
,
20
,
100
,
30
);
jPanel.add(receiveFileLabel);
receiveStatusLabel
=
new
JLabel(
"
ReceiveStatusMessage:
"
);
receiveStatusLabel.setBounds(
360
,
260
,
150
,
30
);
jPanel.add(receiveStatusLabel);
receiveStatusList
=
new
List();
receiveStatusList.setBounds(
360
,
290
,
300
,
200
);
jPanel.add(receiveStatusList);
chooseFileButton
=
new
JButton(
"
ChooseFile
"
);
chooseFileButton.setBounds(
100
,
500
,
110
,
40
);
jPanel.add(chooseFileButton);
chooseFileButton.setToolTipText(
"
选择要发送的文件
"
);
sentButton
=
new
JButton(
"
SentData
"
);
sentButton.setBounds(
400
,
500
,
110
,
40
);
jPanel.add(sentButton);
sentButton.setToolTipText(
"
发送文件
"
);
cleanButton
=
new
JButton(
"
Clean
"
);
cleanButton.setBounds(
700
,
500
,
110
,
40
);
jPanel.add(cleanButton);
cleanButton.setToolTipText(
"
清除信息
"
);
setTitle(
"
StopandWaitProtocolSimulator
"
);
setBounds(
80
,
60
,
900
,
600
);
this
.setLayout(
null
);
this
.setBackground(
new
Color(
2
,
3
,
5
));
this
.setResizable(
false
);
setVisible(
true
);
}
public
boolean
isTout()
...
{
Randomrandom
=
new
Random();
//
System.out.println(random.nextInt(10));
if
(random.nextInt(
10
)
>
8
)
...
{
return
true
;
}
else
...
{
return
false
;
}
//
importjava.lang.Math;
//
System.out.println(Math.random()*10);
}
public
boolean
isCRC_Right()
...
{
Randomrandom
=
new
Random();
//
System.out.println(random.nextInt(10));
if
(random.nextInt(
10
)
>
2
)
...
{
//
isACK=true;
return
true
;
}
else
...
{
//
isACK=false;
return
false
;
}
}
public
void
setSentNum()
...
{
//
if(sentNum=false)
//
sentNum=true;
//
else
//
sentNum=false;
sentNum
=
!
sentNum;
}
public
void
setReceiveNum()
...
{
//
if(receiveNum=false)
//
receiveNum=true;
//
else
//
receiveNum=false;
receiveNum
=
!
receiveNum;
}
public
void
listener()
...
{
//
addWindowListener
addWindowListener(
new
WindowAdapter()
...
{
public
void
windowClosing(WindowEvente)
...
{
System.exit(
0
);
//
System.exit(intstatus);零参数正常终止JVM;非零参数非正常终止(提前)JVM
}
}
);
//
chooseFileButton.addActionListener(
new
ActionListener()
...
{
public
void
actionPerformed(ActionEvente)
...
{
FileDialogfileDialog
=
new
FileDialog(
new
JFrame(),
"
请选择传输文件
"
);
fileDialog.setVisible(
true
);
Filefile
=
new
File(fileDialog.getDirectory()
+
fileDialog.getFile());
/**/
/*
*解析:BufferedReader有readLine()方法;男人就是人(子类对象当着父类对象用)
本文地址:
http://www.45fan.com/dnjc/71945.html
Tags:
协议
停止
模拟
编辑:路饭网
上一篇:
如何在dos下更改ip命令?
下一篇:
Web Service开发实用指南图略介绍
相关文章列表
怎么样下载Win10开发必备预览版10586模拟
如何处理win7系统microsoft注册服务器已
如何处理Win10系统提示Microsoft DirectX
解决VS2010意外停止显示error MSB4014的
解决win10连不上网提示此计算机缺少一个
如何处理酷狗音乐无法播放总"IESandBox.
解决win8.1安装CAD2006无法激活提示停止
怎么样处理win7系统自带画图软件提示已停
使用巷道模拟驾驶系统的步骤
怎么样处理xp系统打开计算机管理弹出"已
推广内容
推荐阅读
热门推荐
推荐文章
·
如何为Excel2010表格中的图表添加说明文
·
Win7系统看电影时,如果有QQ消息,电影声
·
WPS文字文档中,如何给指定的文字添加边
·
盘点制作PPT时常用的一些快捷键大全
·
分享一组Win8系统不太为人所知的小技巧
·
系统遇到特殊故障时,如何进入Win10系统
·
电脑系统损坏要如何修复?修复win10系统
·
想找回关闭的网页该怎么办?怎样查看360
·
实现电脑每天定时关机,借助Win7任务计划
·
什么是Telnet协议?Win7如何开启Telnet服
·
电脑时间出现差错时如何进行北京时间校准
·
电脑运行速度慢,C盘空间越来越小,如何
关于我们
|
联系我们
|
友情链接
|
网站地图
|
Sitemap
|
App
|
返回顶部