????????????
1 package com.lovo.work;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.net.Socket;
7 import java.text.SimpleDateFormat;
8 import java.util.Calendar;
9 import java.util.Date;
10
11 public class MSGThread extends Thread{
12
13     private Socket fromClient;
14     private FeiqiuFrame feiqiuframe;
15
16     public MSGThread(Socket fromClient??FeiqiuFrame feiqiuframe){
17         this.fromClient = fromClient;
18         this.feiqiuframe = feiqiuframe;
19     }
20
21     public void run(){
22         BufferedReader br = null;
23         try {
24             br = new BufferedReader(new InputStreamReader(
25                     fromClient.getInputStream()));
26             String str = br.readLine();
27             String[] allMsg = str.split("&");
28             String str2=MSGThread.this.feiqiuframe.getMsgArea().getText();
29             String str1=allMsg[0] + "?:" + allMsg[1];
30             String str3=str2+" "+getFormatDate()+" "+str1;
31             MSGThread.this.feiqiuframe.setStr3(str3);
32             MSGThread.this.feiqiuframe.getMsgArea().setText(MSGThread.this.feiqiuframe.getStr3());
33 //        System.out.println(str2);
34 //        System.out.println(str1);
35 //        System.out.println(str3);
36
37         } catch (IOException e) {
38             // TODO Auto-generated catch block
39             e.printStackTrace();
40         } finally{
41             if(br != null){
42                 try {
43                     br.close();
44                 } catch (IOException e) {
45                     // TODO Auto-generated catch block
46                     e.printStackTrace();
47                 }
48             }
49             if(this.fromClient != null){
50                 try {
51                     this.fromClient.close();
52                 } catch (IOException e) {
53                     // TODO Auto-generated catch block
54                     e.printStackTrace();
55                 }
56             }
57         }
58
59
60     }
61
62     public static String getFormatDate()
63     {
64         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
65         return sdf.format(Calendar.getInstance().getTime());
66     }
67
68 }