java聊天代码

java聊天代码

ID:42463256

大小:28.02 KB

页数:18页

时间:2019-09-15

java聊天代码_第1页
java聊天代码_第2页
java聊天代码_第3页
java聊天代码_第4页
java聊天代码_第5页
资源描述:

《java聊天代码》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、服务器代码:WindowServer.javaimportjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.io.IOException;imp

2、ortjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JList;importjavax.swing.JOptionPane;importjavax.swing.JScrollPane;importjavax.swing.JTextArea;importjavax.swing.JTextField;importjavax.swing.border.TitledBorder

3、;publicclassWindowServer{publicstaticJFramewindow;publicstaticJTextAreatextMessage;//聊天记录publicstaticJListuser;//用户列表publicstaticintports;JButtonstart,send,exit;JTextFieldportServer,message,name;//主函数入口publicstaticvoidmain(String[]args){newWin

4、dowServer();}//初始化窗体publicWindowServer(){init();}//初始化内容publicvoidinit(){//采用绝对布局window=newJFrame("服务端");window.setLayout(null);window.setBounds(200,200,500,400);window.setResizable(false);//不可改变大小JLabellabel1=newJLabel("端口号:");label1.setBounds(10,8,5

5、0,30);window.add(label1);portServer=newJTextField();portServer.setBounds(60,8,100,30);portServer.setText("30000");window.add(portServer);JLabelnames=newJLabel("用户名:");names.setBounds(180,8,55,30);window.add(names);name=newJTextField();name.setBounds(2

6、30,8,60,30);name.setText("服务端");window.add(name);start=newJButton("启动");start.setBounds(300,8,80,30);window.add(start);exit=newJButton("关闭");exit.setBounds(390,8,80,30);window.add(exit);JLabellabel2=newJLabel("用户列表");label2.setBounds(40,40,80,30);wind

7、ow.add(label2);user=newJList();JScrollPanescrollPane=newJScrollPane(user);//添加滚动条scrollPane.setBounds(10,70,120,220);window.add(scrollPane);textMessage=newJTextArea();textMessage.setBounds(135,70,340,220);textMessage.setBorder(newTitledBorder(

8、"聊天记录"));//设置标题textMessage.setEditable(false);//不可编辑//文本内容换行的两个需要配合着用textMessage.setLineWrap(true);//设置文本内容自动换行,在超出文本区域时,可能会切断单词textMessage.setWrapStyleWord(true);//设置以自动换行,以单词为整体,保证单词不会被切断JScrollPanescrollPane1=newJScrollPane(textMessage);//设

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。