JFrameDis

import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JFrameDis extends Thread {
 private DataInputStream inFromClient;
 private DataOutputStream outToClient;
 ServerSocket serverSocket;
 Socket connectToClient;
 String str;
 
 private static JFrame mainJFrame;
 private static JLabel myLabel;
 private static JTextArea myText;
 private static Container con;
 private static JPanel myPanel;
 private static JScrollPane JSPane;
 private static JTable myTable;
 static int i = 0;
 
 public static void demo(){
  {
   mainJFrame = new JFrame("服务器接收");
   con = mainJFrame.getContentPane();
   //mainJFrame.setLayout(new FlowLayout());
   myText = new JTextArea();
   myText.setEditable(false);
   myText.setLineWrap(true);
   myText.setText(null);
   JSPane = new JScrollPane(myText);
   con.add(JSPane,BorderLayout.CENTER);
   myLabel = new JLabel(" mmm");
   myPanel = new JPanel();
   myPanel.setLayout(new FlowLayout());
   myPanel.add(myLabel);
   con.add(myLabel,BorderLayout.SOUTH);
   mainJFrame.setSize(600,450);
   mainJFrame.setVisible(true);
   mainJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   i++;
  }
 }
 public JFrameDis(Socket socket) throws IOException{
 
  
  
  connectToClient = socket;
  inFromClient = new DataInputStream(connectToClient.getInputStream());
  outToClient  = new DataOutputStream(connectToClient.getOutputStream());
  start();
  
 }
 
 public void run(){
  
  while(true){
   try{
    String data[],data1[];
    str = inFromClient.readUTF();
    if(str.length() > 0){
     
    System.out.println(str);
    data = str.split("data");
    for(int i = 0;i <=data.length;i++){
     data1 = data[i].split("#");
     myText.append(data1[1] + "\r\n");
    
     
    }
     
    }
   }catch(IOException e){}
  }
 }

}


你可能感兴趣的:(socket,import,private,public)