ImageVerifierCode 换一换
格式:DOCX , 页数:56 ,大小:33.94KB ,
资源ID:4770862      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4770862.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java局域网聊天全部源码.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

java局域网聊天全部源码.docx

1、java局域网聊天全部源码package com.socket.tcp.basechat;import java.awt.BorderLayout;import java.awt.EventQueue;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JO

2、ptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.border.EmptyBorder;/* * 登陆窗口。 * author lucky star * */public class LoginChat extends JDialog private final JPanel contentPanel = new JPanel(); private JTextField userNameField; /* * Launch the application.b */ publi

3、c static void main(String args) try LoginChat dialog = new LoginChat(); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); catch (Exception e) e.printStackTrace(); /* * Create the dialog. */ public LoginChat() setLocationByPlatform(true); setBounds(100, 100, 450, 114

4、); getContentPane().setLayout(new BorderLayout(); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); JLabel label = new JLabel(u7528u6237u540DuFF1A); label.setBounds(10, 10, 54, 15); contentPanel.add(label); user

5、NameField = new JTextField(); userNameField.setBounds(75, 7, 349, 21); contentPanel.add(userNameField); userNameField.setColumns(10); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT); getContentPane().add(buttonPane, BorderLayout.SOUTH); JButton okButton = new

6、JButton(OK); okButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent actionevent) String txt = userNameField.getText(); if (txt = null | .equals(txt) JOptionPane.showMessageDialog(LoginChat.this, 请输入用户名,提示,JOptionPane.WARNING_MESSAGE); userNameField.requestFocus(); re

7、turn; EventQueue.invokeLater(new Runnable() public void run() try Main frame = new Main(userNameField .getText(); frame.setVisible(true); catch (Exception e) e.printStackTrace(); ); LoginChat.this.dispose(); ); okButton.setActionCommand(OK); buttonPane.add(okButton); getRootPane().setDefaultButton(o

8、kButton); JButton cancelButton = new JButton(Cancel); cancelButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent actionevent) LoginChat.this.dispose(); ); cancelButton.setActionCommand(Cancel); buttonPane.add(cancelButton); package com.socket.tcp.basechat;import java

9、.awt.BorderLayout;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.GraphicsEnvironment;import java.awt.Image;import java.awt.MenuItem;import java.awt.Panel;import java.awt.PopupMenu;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.Transferable

10、;import java.awt.datatransfer.UnsupportedFlavorException;import java.awt.dnd.DnDConstants;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetDragEvent;import java.awt.dnd.DropTargetDropEvent;import java.awt.dnd.DropTargetEvent;import java.awt.dnd.DropTargetListener;import java.awt.event.Ac

11、tionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.BufferedInputStream;import java.i

12、o.DataInputStream;import java.io.DataOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.RandomAccessFile;import .InetAddress;import .ServerSocket;import .Socket;import .UnknownHo

13、stException;import java.util.ArrayList;import java.util.List;import javax.imageio.ImageIO;import javax.swing.DefaultComboBoxModel;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JColorChooser;import javax.swing.JComboBox;import javax.swing.JDia

14、log;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextArea;import javax.swing.JTextPane;import javax.sw

15、ing.ListSelectionModel;import javax.swing.border.EmptyBorder;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.filechooser.FileFilter;import javax.swing.table.TableModel;import javax.swing.text.AttributeSet;import javax.swing.text.BadLocationException;im

16、port javax.swing.text.Document;import javax.swing.text.SimpleAttributeSet;import javax.swing.text.StyleConstants;/* * 实现群、私聊、发送文字、图片、文件。 * 文件支持单次同时发送7个,多线程接收。 * author lucky star * */public class Main extends JFrame private JPanel contentPane; private JTextPane sendPane = null; private JTextPane rec

17、vPane = null; private JList onlineList = null; private JButton sendFileBtn = null, recvFileBtn = null; / 发送和接收的进度条 / private JProgressBar sendProgressBar = null, recvProgressBar = null; / 要发送的文件 private List sendFiles = new ArrayList(); / 要接收的文件 private List recvFiles = new ArrayList(); / 文件发送进度 pri

18、vate int fileLen = 0; / chat use TCP protocol private Socket s = null; private ObjectOutputStream oos = null; private Document doc = null; private Document slDoc = null; private String user = null; / 是否勾选私聊 private boolean isSL = false; / 与哪个私聊 private String slUser = null; / 私聊面板 private JTextPane

19、sltextPane = null; private Font f = null; / 字体对话框返回的字体。 / 发送和接受消息面板的样式 private SimpleAttributeSet msgAttrSet = new SimpleAttributeSet(); / 显示发送人和时间的样式 private SimpleAttributeSet tipAttrSet = null; private JTable table; public Font getF() return f; public void setF(Font f) this.f = f; /* * Launch the

20、 application. */ /* * public static void main(String args) EventQueue.invokeLater(new * Runnable() public void run() try Main frame = new Main(); * frame.setVisible(true); catch (Exception e) e.printStackTrace(); * ); */ / connect to server public void connect() try s = new Socket(InetAddress.getLoc

21、alHost(), 8888); oos = new ObjectOutputStream(s.getOutputStream(); catch (UnknownHostException e) / TODO Auto-generated catch block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); / send msg to server public void sendMsg(MsgInfo mi) try oos.writeObje

22、ct(mi); oos.flush(); catch (IOException e) System.out.println(send msg failed.); e.printStackTrace(); / disconnect to server when exit. public void disconnect() try if (oos != null) oos.close(); if (s != null) s.close(); catch (IOException e) System.out.println(exit chat.); e.printStackTrace(); publ

23、ic void insertString(String str, AttributeSet attributeset) try doc.insertString(doc.getLength(), str, attributeset); catch (BadLocationException e) / TODO Auto-generated catch block e.printStackTrace(); public void insertImg(Image img) recvPane.insertIcon(new ImageIcon(img); /* * Create the frame.

24、*/ public Main(String user) this.user = user; setTitle(User + user); FontAttr fa = new FontAttr(new Font(楷体, Font.PLAIN, 12), Color.BLUE, Color.WHITE); tipAttrSet = fa.getAttributeSet(); setF(new Font(楷体, Font.PLAIN, 12); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 773, 651);

25、 setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5); setContentPane(contentPane); contentPane.setLayout(null); JScrollPane jscrollPane1 = new JScrollPane(); jscrollPane1.setBounds(0, 28, 432, 199); contentPane.add(jscrollPane1); recvPane = new

26、JTextPane(); jscrollPane1.setViewportView(recvPane); recvPane.setEditable(false); doc = recvPane.getStyledDocument(); JButton imgBtn = new JButton(u56FEu7247); imgBtn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) / 选择图片 JFileChooser jfc = new JFileChooser(); jf

27、c.setDialogTitle(选择一张图片); jfc.setFileFilter(new FileFilter() private String accepts = jpg, jpeg, gif, png, bmp ; Override public String getDescription() / TODO Auto-generated method stub return null; Override public boolean accept(File arg0) boolean b = false; for (String s : accepts) if (arg0.getNa

28、me().endsWith(s) b = true; break; return b; ); int r = jfc.showOpenDialog(Main.this); if (r = JFileChooser.APPROVE_OPTION) / 确定 File f = jfc.getSelectedFile(); List imgs = new ArrayList(); imgs.add(f); MsgInfo mi = new MsgInfo(); mi.setSender(Main.this.user); mi.setImgs(imgs); if (isSL) / 私聊 mi.setUser(slUser); / 将图片添加到私聊窗口 try try slDoc.insertString( slDoc.getLength(), Main.this.user +

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1