資源簡介
在線聊天系統(java代碼)就是說,可以有多個客戶端..可以實現在線聊天功能
代碼片段和文件信息
package?clile;
import?javax.swing.*;
import?java.awt.*;
import?java.awt.event.*;
import?java.io.*;
import?java.net.*;
class?Myframe?extends?Jframe?implements?RunnableActionListener?
{??JTextField?textAtextBtextC;
???JTextArea?showAreaA;
???JButton?connectsend;
???Socket?socket=null;
???DataInputStream?in=null;
???DataOutputStream?out=null;
???Thread?thread;
???Myframe()?
???{
??????super(“Clile“);
??setLayout(new?FlowLayout());
??
??textA=new?JTextField(15);textB=new?JTextField(5);textC=new?JTextField(20);
??showAreaA=new?JTextArea(1045);
??????????connect=new?JButton(“連接“);send=new?JButton(“發送“);
??????????JPanel?pane1=new?JPanel();
??JPanel?pane2=new?JPanel();
??JPanel?pane3=new?JPanel();
??pane1.add(new?JLabel(“server?IP:“));
??pane1.add(textA);
??pane1.add(new?JLabel(“port:“));
??pane1.add(textB);
??pane2.add(showAreaA);pane3.add(textC);
??pane3.add(connect);pane3.add(send);
??add(pane1BorderLayout.NORTH);
??add(pane2BorderLayout.CENTER);
??add(pane3BorderLayout.SOUTH);
??????????connect.addActionListener(this);
??????????send.addActionListener(this);
?????
??????setSize(600400);
??????setBounds(100100600350);
??????setVisible(true);
??????setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
??????validate();???
???}
????public?void?actionPerformed(ActionEvent?e)
????{
????????if(e.getSource()==connect)
????????{
????????????try
??{
????????????????????String?ip=textA.getText();
???????????????????int?p=Integer.parseInt(textB.getText());
???????????????????socket=new?Socket(ipp);
???in=new?DataInputStream(socket.getInputStream());
???out=new?DataOutputStream(socket.getOutputStream());
???thread=new?Thread(this);
???thread.start();
???????????????????out.writeUTF(“已與客戶端連接“);
??????????}
?catch(IOException?ee)
?{
?System.out.println(ee);
?}
????????}
????????if(e.getSource()==send)
????????{
????????????String?s=textC.getText();
?if(s!=null)
??????????{?
?????try{?out.writeUTF(s);}
?????catch(IOException?el){}
??}
????????}
????}
????public?void?run()//對接收信息的處理
????{?
??????String?s=null;
??????while(true)
??????{?
????????????try
???????????????{?s=in.readUTF();
?????????????????showAreaA.append(s+“\n“);
?????????}
?catch(IOException?e)
?{
?showAreaA.append(“與服務器已斷開“+e);
?????break;
?}
????}
}
}
public?class?clile
{
?????public?static?void?main(String?args[])
?????{
????????Myframe?f=new?Myframe();
?????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????232??2008-11-17?08:30??liaotian\.classpath
?????文件????????384??2008-11-17?08:30??liaotian\.project
?????文件???????2635??2008-11-17?08:37??liaotian\src\server\server.java
?????文件???????2556??2008-11-17?08:37??liaotian\src\clile\clile.java
?????文件??????????0??2008-12-23?10:03??liaotian\src\clile\sada.java
?????文件???????3611??2008-12-23?10:07??liaotian\bin\server\Myfr
?????文件????????445??2008-12-23?10:07??liaotian\bin\server\server.class
?????文件????????438??2008-12-23?10:07??liaotian\bin\clile\clile.class
?????文件???????3707??2008-12-23?10:07??liaotian\bin\clile\Myfr
?????目錄??????????0??2008-12-31?14:47??liaotian\src\server
?????目錄??????????0??2008-12-31?14:47??liaotian\src\clile
?????目錄??????????0??2008-12-31?14:47??liaotian\bin\server
?????目錄??????????0??2008-12-31?14:47??liaotian\bin\clile
?????目錄??????????0??2008-12-31?14:47??liaotian\src
?????目錄??????????0??2008-12-31?14:47??liaotian\bin
?????目錄??????????0??2008-12-31?14:47??liaotian
-----------?---------??----------?-----??----
????????????????14008????????????????????16
評論
共有 條評論