java实现聊天室功能(包含全部代码-有界面)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
服务器端代码:
import .*;
import .*;
import .*;
import .*;
public class Server
{
private static final int PORT=6666;
G_Menu gm=new G_Menu();
private ServerSocket server;
public ArrayList
public static String user;
public static ArrayList
while(true)
{
Socket client=();etServer();
}
class Chat implements Runnable
{
Socket socket;
private BufferedReader br;
private String msg;
private String mssg="";
public Chat(Socket socket)
{
try{
=socket;
}catch(Exception ex){
();
}
}
public void run()
{
try{
br=new BufferedReader(new InputStreamReader()));
while((msg=())!=null)
{
if("1008611"))plit(":");quals()+"("+()+")"))etOutputStream());quals ()))etOutputStream());quals(si[0]))lose();;
import .*;
import .*;
import class Socket_one;
import .*;
import .*;
import Landen extends Frame implements ActionListener {
JFrame jf=new JFrame("聊天登陆");
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JPanel jp4=new JPanel();
JLabel jl1=new JLabel("姓名:");
JLabel jl2=new JLabel("地址:");
JLabel jl3=new JLabel("端口:");
JRadioButton jrb1=new JRadioButton("男生"); JRadioButton jrb2=new JRadioButton("女生"); JRadioButton jrb3=new JRadioButton("保密");
public JTextField jtf1=new JTextField(10);
public JTextField jtf2=new JTextField(10);
public JTextField jtf3=new JTextField(10);
JButton jb1=new JButton("连接");
JButton jb2=new JButton("断开");
TitledBorder tb=new TitledBorder("");
ButtonGroup gb=new ButtonGroup();
public void init()quals("断开"))
{
(0);
}
if().equals("连接"))
{
if().equals(""))
{
(null,"请输入用户名!");
}
else if(!()&&!()&&!())
{
(null,"请选择性别!");
}
else
{
(false);
if())
{
s1="boy";
}
else if())
{
s1="girl";
}
else if())
{
s1="secret";
}
G_Menu gmu=new G_Menu();
(),s1);
();
}
}
}
}
public class Login
{
public static void main(String[] args) {
new Landen().init();
}
}
主界面代码:
import .*;
import .*;
import .*;
import .*;
class G_Menu extends JFrame implements ActionListener {
JFrame jf=new JFrame("聊天室");
public Socket_one soc;
public PrintWriter pw;
public JPanel jp1=new JPanel();
public JPanel jp2=new JPanel();
public JPanel jp3=new JPanel();
public JPanel jp4=new JPanel();
public JPanel jp5=new JPanel();
public JPanel jp6=new JPanel();
public JPanel jp7=new JPanel();
public static JTextArea jta1=new JTextArea(12,42); public static JTextArea jta2=new JTextArea(12,42);
public JLabel jl1=new JLabel("对");
public static JComboBox jcomb=new JComboBox();
public JCheckBox jcb=new JCheckBox("私聊");
public JTextField jtf=new JTextField(36);
public JButton jb1=new JButton("发送>>");
public JButton jb2=new JButton("刷新");
public static DefaultListModel listModel1;
public static JList lst1;
public String na;
public String se;
public String message;