⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code.htm

📁 本程序是用java编写的一些关于arq协议实现的小程序
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<br><font face="Courier New,Courier"><font size=-1>&nbsp; stop = new Button("StopAnimation");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; stop.setActionCommand("stopanim");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; stop.addActionListener(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; fast = new Button("Faster");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; fast.setActionCommand("fast");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; fast.addActionListener(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; slow = new Button("Slower");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; slow.setActionCommand("slow");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; slow.addActionListener(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; kill = new Button("KillPacket");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; kill.setActionCommand("kl");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; kill.addActionListener(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; kill.setEnabled(false);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; reset = new Button("Reset");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; reset.setActionCommand("rst");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; reset.addActionListener(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; // Adding thebuttons</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; add(send);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; add(stop);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; add(fast);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; add(slow);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; add(kill);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; add(reset);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; }</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;public void start()</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; if (gbnThread==null)&nbsp;&nbsp;&nbsp;&nbsp;// Creating main thread and start it</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; gbnThread= new Thread(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; gbnThread.start();</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; }</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;public void run()</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; Thread currenthread= Thread.currentThread();</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; while (currenthread==gbnThread)&nbsp;&nbsp;// While the animation is running</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; if (onTheWay(sender))&nbsp;&nbsp;&nbsp;// Checks if any of the packets are travelling</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;total_packet; i++)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;if (sender[i]!= null)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (sender[i].on_way)&nbsp;&nbsp;&nbsp;&nbsp; // If packet is roaming</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (sender[i].packet_pos &lt; (v_clearance-pack_height))</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[i].packet_pos+=5;&nbsp; // Move packet</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (sender[i].packet_ack)&nbsp; // If it is moving to destination</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[i].reached_dest = true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (check_upto_n(i))&nbsp;&nbsp; // Send acknowledgement if all preceeding</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // packets are received.</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[i].packet_pos = pack_height+5;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[i].packet_ack = false;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statusMsg = "Packet "+i+" received. Acknowledge sent.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[i].on_way = false;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statusMsg = "Packet "+i+" received. No acknowledge sent.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i==selected)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected = -1;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kill.setEnabled(false);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (!sender[i].packet_ack)&nbsp;&nbsp; // acknowledgement</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statusMsg = "Packet "+ i +" acknowledge received.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[i].on_way = false;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int n=0; n&lt;=i; n++)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[n].acknowledged = true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i==selected)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selected = -1;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kill.setEnabled(false);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timerThread = null;&nbsp;&nbsp;&nbsp; //resetting timer thread</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i+window_len&lt;total_packet)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base = i+1;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (nextseq &lt; base+window_len) send.setEnabled(true);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (base != nextseq)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statusMsg += " Timer restarted.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timerThread = new Thread(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timerSleep = true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timerThread.start();</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statusMsg += " Timer stopped.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; strCurrentValues= "Window Base = "+ base +".&nbsp;&nbsp; Next Sequence No. = "+ nextseq;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; repaint();</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; try{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(1000/fps);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;} catch (InterruptedException e)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Help");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; }</font></font>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -