ARQ協(xié)議模擬實(shí)現(xiàn)java.doc_第1頁(yè)
ARQ協(xié)議模擬實(shí)現(xiàn)java.doc_第2頁(yè)
ARQ協(xié)議模擬實(shí)現(xiàn)java.doc_第3頁(yè)
ARQ協(xié)議模擬實(shí)現(xiàn)java.doc_第4頁(yè)
ARQ協(xié)議模擬實(shí)現(xiàn)java.doc_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Timer.java文件package common;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.text.SimpleDateFormat;import java.util.Date;import javax.swing.Timer;import javax.swing.JTextField;public class TimeDate now ; Timer timer; JTextField lbl; public Time( JTextField l) lbl=l; timer = new Timer(1000, new ActionListener() public void actionPerformed(ActionEvent e) now = new Date(now.getTime() - 1000); SimpleDateFormat formatter = new SimpleDateFormat(HH:mm:ss); lbl.setText(formatter.format(now); ); SuppressWarnings(deprecation)public void time_start() / lbl.setText(00:00:10); now = new Date(); now.setHours(0); now.setMinutes(0); now.setSeconds(10); timer.start(); public void time_stop() timer.stop(); lbl.setText(00:00:10); public void time_restart(); timer.stop();this.time_start(); ARQ.java文件import java.awt.*;import java.awt.event.*;import javax.swing.BoxLayout;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JButton;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.ButtonGroup;import javax.swing.JTable;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import javax.swing.table.*;import javax.swing.text.Document;import java.io.FileWriter;import java.io.IOException;import common.Time;public class ARQ extends JFrame private static final long serialVersionUID = -5437589209629747957L; private int NUM; private Time T; private JTextField status; private JButton b; private JRadioButton r; DefaultTableModel m_data; JTable m_view; FileWriter f1; FileWriter f2; FileWriter f3;public ARQ() throws IOException super(ARQ); NUM=0; Container c=getContentPane(); c.setLayout(new FlowLayout(); JPanel P=new JPanel2; P0=new JPanel(); P0.setLayout(new BoxLayout(P0,BoxLayout.X_AXIS); c.add(P0); P1=new JPanel(); c.add(P1); JPanel Q=new JPanel2; Q0=new JPanel(); Q0.setLayout(new BoxLayout(Q0,BoxLayout.Y_AXIS); P0.add(Q0); Q1=new JPanel(); Q1.setLayout(new BoxLayout(Q1,BoxLayout.Y_AXIS); P0.add(Q1); JPanel R=new JPanel4; R0=new JPanel(); R0.setLayout(new FlowLayout(FlowLayout.LEFT); Q0.add(R0); R1=new JPanel(); R1.setLayout(new FlowLayout(FlowLayout.LEFT); Q0.add(R1); R2=new JPanel(); R2.setLayout(new FlowLayout(FlowLayout.LEFT); Q0.add(R2); R3=new JPanel(); R3.setLayout(new FlowLayout(FlowLayout.CENTER); Q0.add(R3); /文件 f1=new FileWriter(f1.txt,true); f2=new FileWriter(f2.txt,true); f3=new FileWriter(f3.txt,true); /數(shù)據(jù)發(fā)送狀態(tài) JTextField s=new JTextField(新數(shù)據(jù),7), new JTextField(重發(fā),7) , new JTextField(倒計(jì)時(shí),4), new JTextField(00:00:10,10), new JTextField(數(shù)據(jù),4), new JTextField(,15) ; /數(shù)據(jù)發(fā)送住狀態(tài) status=s; status0.setEditable(false); status1.setEditable(false); status2.setEditable(false); status4.setEditable(false); status1.setEnabled(false); JLabel l=new JLabel(狀態(tài): ); R0.add(l); R0.add(status0); R1.add(status2); R1.add(status3); R2.add(status4); R2.add(status5); b=new JButton(發(fā)送); b.setEnabled(false); R3.add(b); JLabel l1=new JLabel(選擇操作); Q1.add(l1); / 選擇操作 JRadioButton r1=new JRadioButton(ACK), new JRadioButton(NAK), new JRadioButton(不處理), new JRadioButton(初始) ; r=r1; ButtonGroup rg=new ButtonGroup(); for(int i=0;ir.length-1;i+) Q1.add(ri); rg.add(ri); rg.add(r3); / /數(shù)據(jù)收發(fā)住狀態(tài)列表 m_data=new DefaultTableModel(); m_view=new JTable(m_data); m_view.setPreferredScrollableViewportSize(new Dimension(300,230); /表格大小 m_view.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JScrollPane sPane=new JScrollPane(m_view); P1.add(sPane); T=new Time(status3); /發(fā)送操作 b.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) T.time_start(); newtore();status0.setText(新數(shù)據(jù));r3.setSelected(true); ); / 時(shí)間顯示 監(jiān)聽(tīng) Document dt = status3.getDocument(); dt.addDocumentListener(new DocumentListener() public void changedUpdate(DocumentEvent e) ; public void insertUpdate(DocumentEvent e) if(status3.getText().toString().equals(00:00:00) T.time_restart(); newtore(); String s=status5.getText().toString(); mb_addRow(s, 超時(shí),重發(fā),); public void removeUpdate(DocumentEvent e) ; ); /輸入監(jiān)聽(tīng) Document dt1 = status5.getDocument(); dt1.addDocumentListener(new DocumentListener() public void changedUpdate(DocumentEvent e) public void insertUpdate(DocumentEvent e) if(!status5.getText().toString().equals() b.setEnabled(true); ; public void removeUpdate(DocumentEvent e) if(status5.getText().toString().equals() b.setEnabled(false); ; ); /按鈕監(jiān)聽(tīng) r0.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) T.time_stop(); retonew(); status5.setText(); status5.requestFocus(); ); r0.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String s=status5.getText().toString();NUM+; mb_addRow(s, ACK,接受 +NUM,s); /NUM+ int裝化為string ); r1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) T.time_restart();newtore(); ); r1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String s=status5.getText().toString(); mb_addRow(s, NCK,重發(fā),); /NUM+ int裝化為string ); r2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) T.time_restart();newtore(); ); r2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String s=status5.getText().toString(); mb_addRow(s, 不處理,重發(fā),); /NUM+ int裝化為string ); / /獲取焦點(diǎn) this.addWindowListener(new java.awt.event.WindowAdapter() public void windowActivated(java.awt.event.WindowEvent e) status5.requestFocusInWindow(); mb_addColumn(); ); /關(guān)閉文件 this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) try f1.close();f2.close(); f3.close(); catch (IOException e1) e1.printStackTrace(); ); /重發(fā)狀態(tài)public void newtore()status0.setText(重發(fā));b.setEnabled(false);r0.setEnabled(true);r1.setEnabled(true);r2.setEnabled(true);|/新信息狀態(tài)public void retonew()status0.setText(新數(shù)據(jù));b.setEnabled(true);r0.setEnabled(false);r1.setEnabled(false);r2.setEnabled(false);/添加一行public vo

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論