java課程設(shè)計(jì)報(bào)告qq聊天_第1頁
java課程設(shè)計(jì)報(bào)告qq聊天_第2頁
java課程設(shè)計(jì)報(bào)告qq聊天_第3頁
java課程設(shè)計(jì)報(bào)告qq聊天_第4頁
java課程設(shè)計(jì)報(bào)告qq聊天_第5頁
已閱讀5頁,還剩46頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

河南工業(yè)大學(xué)課程設(shè)計(jì)課程設(shè)計(jì)名稱:java聊天系統(tǒng)專業(yè)班級:學(xué)生姓名:xiaoyang學(xué)號(hào):指導(dǎo)教師:王高平課程設(shè)計(jì)時(shí)間:計(jì)科專業(yè)課程設(shè)計(jì)任務(wù)書學(xué)生姓名Xiaoyang專業(yè)班級計(jì)科f1401學(xué)號(hào)題目聊天系統(tǒng)課題性質(zhì)其他課題來源自擬課題指導(dǎo)教師王高平同組姓名重要內(nèi)容Eclipse,mysql,java網(wǎng)絡(luò)通信,輸入輸出流,類旳對象,以及封裝,多態(tài)實(shí)現(xiàn)聊天功能,局域網(wǎng)下旳聊天系統(tǒng)任務(wù)規(guī)定綜合運(yùn)用java知識(shí),實(shí)現(xiàn)對輸入輸出流旳運(yùn)用,以及對面向?qū)ο髸A基本運(yùn)用,與此同步還要學(xué)會(huì)數(shù)據(jù)庫連接旳使用,以及基本語法,jdbc。參照文獻(xiàn)[1]詹英.數(shù)據(jù)庫技術(shù)與應(yīng)用[M].北京:清華大學(xué)出版社.2023.9-14[2]黃德才.數(shù)據(jù)庫原理及其應(yīng)用教程.[M].北京:科學(xué)出版社.2023.12-3[3]龔沛曾,楊志強(qiáng).數(shù)據(jù)庫技術(shù)與應(yīng)用[M].北京高等教育出版社.2023[4]任滿杰.數(shù)據(jù)庫實(shí)用教程[M].電子工業(yè)出版社.2023[5]王珊,薩師煊.數(shù)據(jù)庫系統(tǒng)概論[M].高等教育出版社出版.2023審查意見指導(dǎo)教師簽字:教研室主任簽字:年月日闡明:本表由指導(dǎo)教師填寫,由教研室主任審核后下達(dá)給選題學(xué)生,裝訂在設(shè)計(jì)(論文)首頁1需求分析運(yùn)用java語言實(shí)現(xiàn)一種聊天局域網(wǎng)系統(tǒng),重要功能實(shí)現(xiàn)信息旳互相交流,整個(gè)程序分三個(gè)大模塊,第一種模塊是服務(wù)器端旳設(shè)計(jì),第二個(gè)模塊是客戶端旳實(shí)現(xiàn),第三個(gè)模塊是數(shù)據(jù)庫連接旳實(shí)現(xiàn)。重要實(shí)現(xiàn)一種客戶端發(fā)送串字符信息,另一端客戶端能接受(在一種局域網(wǎng)下),同步建立了一種數(shù)據(jù)庫(mysql),用于注冊顧客,同步存儲(chǔ)顧客旳信息,以及找回密碼要用到旳密保問題答案。2概要設(shè)計(jì)通過密保找回密碼錯(cuò)誤通過密保找回密碼錯(cuò)誤登錄成功? 否!成功? 否! 注冊賬號(hào)無該賬號(hào) 是 注冊賬號(hào)無該賬號(hào)好友列表好友列表一種一種好友聊天框另一種好友聊天框服務(wù)器 另一種好友聊天框服務(wù)器重要類:JF類:重要是登錄窗口Cell類:按鈕類Findpassword.java:找回密碼類Look:注冊窗口Lookpassword.java:查看密碼窗口Register.java:注冊賬號(hào)類JavaMysql.java:數(shù)據(jù)庫類,連接數(shù)據(jù)庫。3運(yùn)行環(huán)境(軟、硬件環(huán)境)Windows,64位pc機(jī),jvm(java虛擬機(jī))4開發(fā)工具和編程語言Eclipse,java5詳細(xì)設(shè)計(jì)Server.java(實(shí)現(xiàn)一種小型旳服務(wù)器)packagesever;importjava.io.*;.*;importjava.util.*;publicclassSever{ booleanstarted=false; ServerSocketss=null;List<Client>clients=newArrayList<Client>();publicstaticvoidmain(String[]args){ newSever().start(); }publicvoidstart(){ try{ ss=newServerSocket(9999); started=true; }catch(BindExceptione){ System.out.println("端口使用中...."); System.out.println("請關(guān)掉有關(guān)程序并重新運(yùn)行服務(wù)器!"); System.exit(0); }catch(IOExceptione){ e.printStackTrace(); } try{ while(started){ Sockets=ss.accept(); Clientc=newClient(s); System.out.println("aclientconnected!"); newThread(c).start(); clients.add(c); //dis.close(); } }catch(IOExceptione){ e.printStackTrace(); }finally{ try{ ss.close(); }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } }classClientimplementsRunnable{ privateSockets; privateDataInputStreamdis=null; privateDataOutputStreamdos=null; privatebooleanbConnected=false; publicClient(Sockets){ this.s=s; try{ dis=newDataInputStream(s.getInputStream()); dos=newDataOutputStream(s.getOutputStream()); bConnected=true; }catch(IOExceptione){ e.printStackTrace(); } } publicvoidsend(Stringstr){ try{ dos.writeUTF(str); }catch(IOExceptione){ clients.remove(this); System.out.println("對方退出了!我從List里面去掉了!"); //e.printStackTrace(); } } publicvoidrun(){//線程體 try{ while(bConnected){ Stringstr=dis.readUTF(); System.out.println(str); for(inti=0;i<clients.size();i++){ Clientc=clients.get(i); c.send(str); } } }catch(EOFExceptione){ System.out.println("Clientclosed!"); }catch(IOExceptione){ e.printStackTrace(); }finally{ try{ if(dis!=null) dis.close(); if(dos!=null) dos.close(); if(s!=null){ s.close(); //s=null; } }catch(IOExceptione1){ e1.printStackTrace(); } } } }}JF類:登錄旳窗口類packagecn.xiaoyang;importjava.awt.Color;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.MouseEvent;importjava.awt.event.MouseListener;importjava.sql.Connection;import;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.ImageIcon;import;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JTextField;publicclassJFextendsJFrameimplementsMouseListener{ privatestaticfinallongserialVersionUID=1L; publicstaticvoidmain(Stringargs[]){ JFf=newJF(); } publicstaticJTextFieldname=newJTextField(20); JLabelnameLab=newJLabel("輸入號(hào):"); publicstaticJPasswordFieldnam=newJPasswordField(20); JLabelnameLa=newJLabel("輸入密碼:"); Stringpath5="pic//x.png"; //背景圖片 ImageIconbackground5=newImageIcon(path5); cellbut=newcell(background5); Fontfnt=newFont("Serief",Font.BOLD,15); Stringpath4="pic//l.png";ImageIconbackground4=newImageIcon(path4);cellbt=newcell(background4);Stringpath3="pic//b.png";ImageIconbackground3=newImageIcon(path3);cellbt2=newcell(background3);Stringpath2="pic//3.png";ImageIconbackground2=newImageIcon(path2); JLabellabel2=newJLabel(background2); publicJF(){ super("測試"); this.setSize(500,334); this.setLocation(300,200); this.setVisible(true); Stringpath="pic//.png"; //背景圖片 ImageIconbackground=newImageIcon(path); //把背景圖片顯示在一種標(biāo)簽里面 JLabellabel=newJLabel(background); label.setLayout(null); //把標(biāo)簽旳大小位置設(shè)置為圖片剛好填充整個(gè)面板 label.setBounds(0,0,this.getWidth(),this.getHeight()); //把內(nèi)容窗格轉(zhuǎn)化為JPanel,否則不能用措施setOpaque()來使內(nèi)容窗格透明 JPanelimagePanel=(JPanel)this.getContentPane(); imagePanel.setOpaque(false); //把背景圖片添加到分層窗格旳最底層作為背景 nameLab.setFont(fnt); nameLab.setForeground(Color.yellow); nameLa.setFont(fnt); nameLa.setForeground(Color.yellow); nameLab.setBounds(160,120,100,30); bt.setBounds(360,120,72,30); bt.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ registerx=newregister(); } }); name.setBounds(250,120,100,30); nameLa.setBounds(160,160,100,30); nam.setBounds(250,160,100,30); bt2.setBounds(360,160,72,30); bt2.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ newfindpassword(); } }); ////nam.setColumns(20); label2.setBounds(65,120,88,83); but.setBounds(185,210,147,30); but.addMouseListener(this); label.add(nameLab); label.add(bt); label.add(bt2); label.add(nam); label.add(nameLa); label.add(label2); label.add(name); label.add(but); this.getLayeredPane().add(label,newInteger(Integer.MIN_VALUE)); this.setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //讓組件可見 } publicvoidmouseClicked(MouseEvente){ char[]a=nam.getPassword(); Strings=newString(a); //System.out.print(s); Stringb="1"; Statementst=null; ResultSetrs=null; booleant=false; booleanx=false; Connectioncon=null; Stringsql="SELECTname,mibao,passwordFROM"; try{ con=newJavaMysql().connnecton(); st=con.createStatement(); rs=st.executeQuery(sql); }catch(ClassNotFoundExceptione2){ //TODOAuto-generatedcatchblock e2.printStackTrace(); }catch(SQLExceptione2){ //TODOAuto-generatedcatchblock e2.printStackTrace(); } try{ while(rs.next()){ String=rs.getString("name");//匹配顧客名 Stringpassword1=rs.getString("password");//匹配密碼 if(.equals(name.getText())){ t=true; if(password1.equals(nam.getText())){ x=true; } } } con.close(); st.close(); rs.close(); }catch(SQLExceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); } if(t){ if(x){ JF2f1=newJF2();//好友列表在這里顯示 this.setVisible(false);//登錄窗口消失 f1.setVisible(true);//好友列表出現(xiàn) }else{ newpassworderror(); } }else{ newlook(); } } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub }};Passerror類:密碼錯(cuò)誤提醒窗口packagecn.xiaoyang;importjavax.swing.JFrame;importjavax.swing.JLabel;publicclasspassworderrorextendsJFrame{ JLabelb=newJLabel("密碼錯(cuò)誤"); publicpassworderror(){ this.add(b); this.setSize(100,100); this.setLocation(300,500); this.setVisible(true); this.setResizable(false); }Findpassword類:找回密碼類packagecn.xiaoyang;importjava.awt.Color;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;publicclassfindpasswordextendsJFrame{ JLabelnameLab2=newJLabel("密保問題:你旳學(xué)號(hào)是多少"); JTextFieldname3=newJTextField(20); Fontfnt=newFont("Serief",Font.BOLD,15); cellbut=newcell("確定");publicfindpassword(){ this.setSize(500,334); this.setLocation(300,200); this.setVisible(true); this.setLayout(null); nameLab2.setFont(fnt); nameLab2.setForeground(Color.green); nameLab2.setBounds(140,150,200,30); name3.setBounds(140,180,100,30); this.add(name3); this.add(nameLab2); but.setBounds(160,240,147,30); but.addActionListener(newActionListener(){ @Override publicvoidactionPerformed(ActionEvente){ Statementst=null; ResultSetrs=null; booleant=false; Connectioncon=null; Stringsql="SELECTname,mibao,passwordFROM";//查找語句 try{ con=newJavaMysql().connnecton(); st=con.createStatement(); rs=st.executeQuery(sql); }catch(ClassNotFoundExceptione2){ //TODOAuto-generatedcatchblock e2.printStackTrace(); }catch(SQLExceptione2){ //TODOAuto-generatedcatchblock e2.printStackTrace(); } try{ while(rs.next()){ Stringmibao=rs.getString("mibao"); Stringname1=rs.getString("name"); Stringpassword1=rs.getString("password"); if(name3.getText().equals(mibao) &&name1.equals(JF.name.getText())){//比較與否相等 newlookpassword(password1);//假如和密保答案相等就輸出 t=true; break; }} if(t==false){ newlook2password(); } }catch(SQLExceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); } try{ con.close(); st.close(); rs.close(); }catch(SQLExceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); } } });this.add(but);}}}Register類:注冊新顧客packagecn.xiaoyang;importjava.awt.Color;importjava.awt.Font;importjava.awt.event.MouseEvent;importjava.awt.event.MouseListener;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JTextField;publicclassregisterextendsJFrameimplementsMouseListener{JTextFieldname1=newJTextField(20); JLabelnameLab=newJLabel("輸入新號(hào):"); JPasswordFieldnam=newJPasswordField(20); JLabelnameLa=newJLabel("輸入密碼:"); JLabelnameLab2=newJLabel("密保問題:你旳學(xué)號(hào)是多少"); JTextFieldname3=newJTextField(20); Fontfnt=newFont("Serief",Font.BOLD,15);//背景圖片cellbut=newcell("確定");publicregister(){ super("注冊"); this.setSize(500,334); this.setLocation(300,200); this.setVisible(true); Stringpath="pic//.png"; //背景圖片 ImageIconbackground=newImageIcon(path); //把背景圖片顯示在一種標(biāo)簽里面 JLabellabel=newJLabel(background); label.setLayout(null); //把標(biāo)簽旳大小位置設(shè)置為圖片剛好填充整個(gè)面板 label.setBounds(0,0,this.getWidth(),this.getHeight()); //把內(nèi)容窗格轉(zhuǎn)化為JPanel,否則不能用措施setOpaque()來使內(nèi)容窗格透明 JPanelimagePanel=(JPanel)this.getContentPane(); imagePanel.setOpaque(false); nameLab.setFont(fnt); nameLab2.setFont(fnt); nameLab.setForeground(Color.yellow); nameLab2.setForeground(Color.green); nameLa.setFont(fnt); nameLa.setForeground(Color.yellow);nameLab.setBounds(140,80,100,30); but.setBounds(160,240,147,30); name1.setBounds(230,80,100,30); nameLa.setBounds(140,120,100,30); nam.setBounds(230,120,100,30); nameLab2.setBounds(140,150,200,30); name3.setBounds(140,180,100,30); label.add(nameLab); label.add(but);label.add(nam); label.add(nameLa); label.add(nameLab2); label.add(name1); label.add(name3); but.addMouseListener(this); this.getLayeredPane().add(label,newInteger(Integer.MIN_VALUE)); this.setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } publicstaticvoidmain(Stringargs[]){ registerf=newregister(); }@Override publicvoidmouseClicked(MouseEvente){ Stringname=name1.getText(); Stringmibao=name3.getText(); Stringpassword=newString(nam.getPassword()); PreparedStatementst=null; Connectioncon=null; Stringsql="INSERTINTO(name,mibao,password)VALUES(?,?,?)";//預(yù)處理指令 try{ con=newJavaMysql().connnecton(); st=con.prepareStatement(sql); }catch(ClassNotFoundExceptione2){ //TODOAuto-generatedcatchblock e2.printStackTrace(); }catch(SQLExceptione2){ //TODOAuto-generatedcatchblock e2.printStackTrace(); }try{ st.setString(1,name);//向數(shù)據(jù)庫輸入賬號(hào) st.setString(2,mibao);//密保答案 st.setString(3,password);//向數(shù)據(jù)庫輸入密碼 st.executeUpdate(); st.close(); con.close(); }catch(SQLExceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); }JF.name.setText(""); JF.nam.setText(""); this.setVisible(false); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub }}JF2類:好友列表packagecn.xiaoyang;importjava.awt.event.WindowAdapter;importjava.awt.event.MouseListener;importjava.awt.event.WindowEvent;importjava.awt.event.MouseEvent;importjava.awt.Color;importjavax.swing.JFrame;importjava.awt.event.ActionListener;importjava.awt.event.WindowEvent;importjava.awt.event.ActionEvent;importjava.awt.Color;importjava.awt.Container;importjava.awt.GridLayout;importjava.awt.Font;importjava.io.DataInputStream;importjava.io.DataOutputStream;importjava.io.IOException;.Socket;.UnknownHostException;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.swing.JButton;importjavax.swing.JLabel;importjavax.swing.JSplitPane;importjavax.swing.JTextArea;importjavax.swing.JPasswordField;importjavax.swing.JScrollPane;importjavax.swing.JPanel;publicclassJF2extendsJFrameimplementsMouseListener{ Stringpath4="pic//m.png";//背景圖片ImageIconbackground4=newImageIcon(path4);cellbt=newcell(background4); publicJF2(){ //準(zhǔn)備好了一種面板 super.setLayout(null); super.setTitle("好友列表"); this.setSize(500,334); this.setLocation(300,200); this.setVisible(true); Stringpath="pic//2.png";//背景圖片ImageIconbackground=newImageIcon(path);//把背景圖片顯示在一種標(biāo)簽里面JLabellabel=newJLabel(background);label.setLayout(null);//把標(biāo)簽旳大小位置設(shè)置為圖片剛好填充整個(gè)面板label.setBounds(0,0,300,140);//把內(nèi)容窗格轉(zhuǎn)化為JPanel,否則不能用措施setOpaque()來使內(nèi)容窗格透明JPanelimagePanel=(JPanel)this.getContentPane();imagePanel.setOpaque(false);//把背景圖片添加到分層窗格旳最底層作為背景Stringpath2="pic//3.png";ImageIconbackground2=newImageIcon(path2);//把背景圖片顯示在一種標(biāo)簽里面JLabellabel2=newJLabel(background2);label2.setLayout(null);label2.setBounds(5,10,88,83);Stringpath3="pic//f.png";ImageIconbackground3=newImageIcon(path3);//把背景圖片顯示在一種標(biāo)簽里面JLabellabel3=newJLabel(background3);label3.setLayout(null);label3.setBounds(0,140,324,22);JLabelname=newJLabel("冰河世紀(jì)()");name.setForeground(Color.orange);name.setLayout(null);name.setBounds(97,10,180,15);label.add(name);JLabelname2=newJLabel("個(gè)性簽名:堅(jiān)持就是勝利");name2.setForeground(Color.GREEN);name2.setLayout(null);name2.setBounds(97,60,300,15);label.add(name2);label.add(label2);this.add(label3); bt.addMouseListener(this); super.add(bt); bt.setBounds(0,162,325,60); this.setSize(300,550); this.setLocation(300,200); this.getLayeredPane().add(label,newInteger(Integer.MIN_VALUE)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); } @Override publicvoidmouseClicked(MouseEvente){JF3f1=null;//提高作用域 try{ f1=newJF3("吻柔哥()");//初始化聊天窗口 }catch(IOExceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); }this.setVisible(true); f1.setVisible(true); } @Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub } @Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub }};JF3類:聊天窗口packagecn.xiaoyang;importjava.awt.Color;importjava.awt.Font;importjava.awt.event.MouseEvent;importjava.awt.event.MouseListener;import;import;importjava.io.IOException;.Socket;import;importjavax.swing.ImageIcon;importjavax.swing.JFrame;importjavax.swing.JScrollPane;importjavax.swing.JTextArea;publicclassJF3extendsJFrameimplementsMouseListener{ Stringpath4="pic//6.png"; ImageIconbackground4=newImageIcon(path4); cellcell2=newcell(background4);staticJTextAreaj1=newJTextArea(3,20); staticJTextAreaj2=newJTextArea(3,20);Socketclient=null;publicJF3(Strings)throwsIOException{ super(s); j1.setLineWrap(true); j2.setLineWrap(true); this.setLayout(null); j1.setBackground(Color.gray); j2.setBackground(Color.WHITE); JScrollPanescr1=newJScrollPane(j1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,//加入滾動(dòng)條 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JScrollPanescr2=newJScrollPane(j2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scr1.setBounds(0,0,600,600); scr2.setBounds(0,600,500,60); cell2.setBounds(500,600,100,60); cell2.addMouseListener(this); Fontfont=newFont("宋體",Font.BOLD,15);//創(chuàng)立一種字體以便其他調(diào)用 j1.setFont(font); j1.setForeground(Color.blue); this.add(scr1); this.add(scr2); this.add(cell2);this.setSize(606,694); this.setLocation(300,200); this.setVisible(true); this.setResizable(false);client=newSocket("localhost",9999);//初始化窗口時(shí),客戶端連接上newThread(newReceive(client)).start();//開始一種新旳進(jìn)程用于接受}@Override publicvoidmouseClicked(MouseEvente){try{ newThread(newSend(client)).start();//開始一種線程用于發(fā)送信息 }catch(IOExceptione1){ //TODOAuto-generatedcatchblock e1.printStackTrace(); }}@Override publicvoidmousePressed(MouseEvente){ //TODOAuto-generatedmethodstub}@Override publicvoidmouseReleased(MouseEvente){ //TODOAuto-generatedmethodstub }@Override publicvoidmouseEntered(MouseEvente){ //TODOAuto-generatedmethodstub}@Override publicvoidmouseExited(MouseEvente){ //TODOAuto-generatedmethodstub }}Send類:用于向服務(wù)器發(fā)送信息packagecn.xiaoyang;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.io.BufferedReader;importjava.io.DataOutputStream;importjava.io.FileNotFoundException;importjava.io.FileReader;importjava.io.IOException;importjava.io.InputStreamReader;.Socket;importjava.text.DateFormat;importjava.util.Date;publicclassSendimplementsRunnable{ privateBufferedReaderconsole;//輸入流 privateDataOutputStreamdos;//輸出流 privatebooleanisRuning=true;publicSend(Socketclient)throwsIOException{ dos=newDataOutputStream(client.getOutputStream());//獲得輸出流 } publicvoidsend(){ DateFormatdf=null; df=DateFormat.getDateTimeInstance(); Strings1=df.format(newDate());//獲得日期 Strings2=JF3.j2.getText(); Strings3="冰河世紀(jì)()"+s1;Strings=s3+":"+"\n"+""+s2;try{ if(null!=s&&!s.equals("")){ dos.writeUTF(s); dos.flush(); JF3.j2.setText("");//每發(fā)送完一種信息編輯框清空 } }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }} publicvoidrun(){//線程體 { send(); } }}Receive類:用于接受信息packagecn.xiaoyang;importjava.io.DataInputStream;importjava.io.IOException;.Socket;publicclassReceiveimplementsRunnable{privateDataInputStreamdis; privatebooleanisRunning=true; publicReceive(Socketclient){ try{ dis=newDataInputStream(client.getInputStream());//獲得輸入流 }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); isRunning=false; } }publicStringreceive(){ Strings=""; try{ s=dis.readUTF();//讀出字符串 }catch(IOExceptione){ e.printStackTrace(); isRunning=false; } returns;}@Override publicvoidrun(){ while(true){ JF3.j1.append(receive());//寫到編輯框上 JF3.j1.append("\n"); } }}Cell:按鈕類packagecn.xiaoyang;importjava.awt.Font;importjavax.swing.ImageIcon;importjavax.swing.JButton;publicclasscellextendsJButton{privatestaticfinallongserialVersionUID=1L;publiccell(ImageIconimg){ super(img);//傳入一種圖片類 //Fontfnt=newFont("Serief",Font.BOLD,20);//設(shè)置字體此處沒用 //this.setFont(fnt); }//加入事件 publiccell(Strings){ super(s);//傳入字符串參數(shù) Fontfnt=newFont("Serief",Font.BOLD,2

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論