⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.java~14~

📁 局域网聊天系统
💻 JAVA~14~
字号:
package com.soft.Team;

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.util.Hashtable;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.applet.Applet.getCodeBase();
/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Client
    extends JFrame implements Runnable{
  JPanel contentPane;
  Socket  socket=null;
  DataInputStream in=null;
  DataOutputStream out=null;
  InputNameTextArea 用户提交昵称界面=null;
  ChatArea 用户聊天界面=null;
  Hashtable listTable;
  Thread thread=null;
  Label 提示条 = new Label();
  XYLayout xYLayout1 = new XYLayout();
  public Client() {
    try {
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      jbInit();
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  /**
   * Component initialization.
   *
   * @throws java.lang.Exception
   */
  private void jbInit() throws Exception {
    contentPane = (JPanel) getContentPane();
    contentPane.setLayout(xYLayout1);
    setSize(new Dimension(400, 300));
    listTable=new Hashtable();
    setTitle("局域网聊天");
    提示条.setText("在连接到服务器,请稍等■■■■■■■■■");
    contentPane.add(提示条, new XYConstraints(34, 91, 326, 47));
  }
  public void start()
   {
     if(socket!=null&&in!=null&&out!=null)
        {  try
              {
                socket.close();
                in.close();
                out.close();

              }
          catch(Exception ee)
              {
              }
        }
     try
        {
         socket = new Socket(this.getCodeBase().getHost(), 6666);
         in=new DataInputStream(socket.getInputStream());
         out=new DataOutputStream(socket.getOutputStream());
        }
     catch (IOException ee)
        {
          提示条.setText("连接失败");
        }
     if(socket!=null)
        {
         InetAddress address=socket.getInetAddress();
         提示条.setText("连接:"+address+"成功");
         用户提交昵称界面.setSocketConnection(socket,in,out);

        }
     if(thread==null)
        {
          thread=new Thread(this);
          thread.start();
        }
   }

 public void stop()
   {
     try
         {
           socket.close();
           thread=null;
         }
     catch(IOException e)
         {

         }
   }
 public void run()
 {
    while(thread!=null)
        {
           if(用户提交昵称界面.get能否聊天()==true)
             {
                用户聊天界面.setName(用户提交昵称界面.getName());
                用户聊天界面.setSocketConnection(socket,in,out);
                提示条.setText("祝聊天愉快!");
                break;
             }
           try
               {
                 Thread.sleep(100);
               }
           catch(Exception e)
               {
               }
        }
 }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -