?? client.java~18~
字號:
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 + -