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

📄 code.htm

📁 本程序是用java编写的一些关于arq协议实现的小程序
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; else</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; gbnThread= null;</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; while (currenthread== timerThread)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; if (timerSleep)</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; timerSleep=false;</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(time_out_sec*1000);</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;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println ("Timer interrupted.");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</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; else</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 n=base; n&lt;base+window_len; n++)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;if (sender[n] != null)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!sender[n].acknowledged)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[n].on_way = true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[n].packet_ack = true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sender[n].packet_pos = pack_height+5;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; timerSleep= true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; if(gbnThread == null)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;{</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;gbnThread = new Thread (this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;gbnThread.start();</font></font><br><font face="Courier New,Courier"><font size=-1>&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; statusMsg= "Packets resent by timer. Timer restarted.";</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; }</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 actionPerformed(ActionEvente)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp; String cmd =e.getActionCommand();</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 (cmd == "rdt"&amp;&amp; nextseq &lt; base+window_len) // Send button is pressed</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; sender[nextseq]= new packet(true,pack_height+5);</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; statusMsg= "Packet "+ nextseq +" sent.";</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; if (base== nextseq)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;// i.e. the window is empty and a new data is getting in</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; statusMsg+= " Timer set for packet "+ base +".";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; if(timerThread == null)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;timerThread = new Thread(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; timerSleep= true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; timerThread.start();</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;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; repaint();</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; nextseq++;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; if (nextseq== base+window_len)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; send.setEnabled(false);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; start();</font></font><br><font face="Courier New,Courier"><font size=-1>&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; else if (cmd== "fast")&nbsp;&nbsp;&nbsp; // Faster button pressed</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; fps+=2;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; statusMsg= "Simulation speed increased by 2 fps.";</font></font><br><font face="Courier New,Courier"><font size=-1>&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; else if (cmd== "slow" &amp;&amp; fps>2)</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; fps-=2;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; statusMsg= "Simulation speed decreased by 2 fps.";</font></font><br><font face="Courier New,Courier"><font size=-1>&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; else if (cmd== "stopanim")</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; gbnThread= null;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; if (timerThread!= null)</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; timerFlag= true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; timerThread= null;&nbsp;&nbsp; // added later</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; stop.setLabel("Resume");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; stop.setActionCommand("startanim");</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; // disableingall the buttons</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; send.setEnabled(false);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; slow.setEnabled(false);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; fast.setEnabled(false);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&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;&nbsp; statusMsg= "Simulation paused.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; repaint();</font></font><br><font face="Courier New,Courier"><font size=-1>&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; else if (cmd== "startanim")</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; {</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; statusMsg= "Simulation resumed.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; stop.setLabel("StopAnimation");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; stop.setActionCommand("stopanim");</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; if (timerFlag)</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; statusMsg+= " Timer running.";</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; timerThread= new Thread(this);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; timerSleep= true;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp;&nbsp; timerThread.start();</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;</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; // enablingthe buttons</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; send.setEnabled(true);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; slow.setEnabled(true);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; fast.setEnabled(true);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; kill.setEnabled(true);</font></font><br><font face="Courier New,Courier"><font size=-1>&nbsp;&nbsp; repaint();&nbsp;&nbsp;&nbsp;// repainted to show new messages</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; start();</font></font><br><font face="Courier New,Courier"><font size=-1>&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; else if (cmd

⌨️ 快捷键说明

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