TCPsocketV2.zip

  • mynameniubi
    了解作者
  • Java
    开发工具
  • 5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-04-08 20:08
    上传日期
1.Java Swing前端部分 2.基于TCP实现的网络聊天小程序。 3.实现包括视频聊天,文字聊天
TCPsocketV2.zip
  • TCPserverV2
  • DataServer.java
    1KB
  • DataHandle.java
    2.2KB
  • TCPsocketV2
  • DataReceive.java
    1.5KB
  • ServerUI.java
    7.9KB
  • DataSender.java
    650B
  • exitListener.java
    499B
内容介绍
package view; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowListener; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.WindowConstants; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import com.github.sarxos.webcam.Webcam; import com.github.sarxos.webcam.WebcamPanel; import com.github.sarxos.webcam.WebcamResolution; public class ServerUI { private static DataSender dsend = null; private ImageIcon headim_image = new ImageIcon("cuit1.jpg"); private ImageIcon camera_image = new ImageIcon("camera.png"); private ImageIcon camera2_image = new ImageIcon("camera2.png"); private ImageIcon type_image = new ImageIcon("type.png"); private ImageIcon submit_image = new ImageIcon("submit.png"); public static void main(String[] args) throws IOException { new ServerUI().windowOpen(); } public void windowOpen() throws IOException { JFrame window = new JFrame("we-chat"); window.setDefaultCloseOperation(3); window.setResizable(false); window.setLayout(null); window.setSize(1000, 800); window.setLocationRelativeTo(null); //输入框 JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBounds(200,600,800,200); window.add(scrollPane_1); JTextArea textArea = new JTextArea(); textArea.setBorder(null); textArea.setLineWrap(true); scrollPane_1.setViewportView(textArea); //头像 JLabel label =new JLabel(headim_image); label.setBounds(0, 0, 200,200); //label.addMouseListener(l); window.add(label); //IP地址库 JPanel listpanel = new JPanel(); listpanel.setBackground(new Color(137, 207, 240)); listpanel.setBounds(0, 200, 200, 1000); listpanel.setLayout(null); JTextField field = new JTextField(); field.setBounds(0, 0, 100, 50); listpanel.add(field); window.add(listpanel); //聊天记录 JScrollPane scrollPane_2 = new JScrollPane(); scrollPane_2.setBounds(200,0,800,550); window.add(scrollPane_2); JTextPane recordPanel = new JTextPane(); recordPanel.setBackground(new Color(202, 235, 216)); recordPanel.setEditable(false); scrollPane_2.setViewportView(recordPanel); //相机 JButton camera = new JButton(camera_image); camera.setBounds(200,550,50,50); camera.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { camera.setEnabled(false); JFrame camera_window = new JFrame("video"); camera_window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); camera_window.setResizable(false); camera_window.setLayout(null); camera_window.setSize(400, 800); camera_window.setLocation(window.getX()+1000, window.getY()); camera_window.setVisible(true); JPanel video1_panel = new JPanel(); video1_panel.setBackground(new Color(137, 207, 240)); video1_panel.setBounds(0,0,400,400); JLabel la = new JLabel(camera2_image); video1_panel.add(la); camera_window.add(video1_panel); JPanel video2_panel = new JPanel(); video2_panel.setBackground(new Color(137, 207, 240)); video2_panel.setBounds(0,400,400,400); camera_window.add(video2_panel); Webcam webcam = Webcam.getDefault(); webcam.setViewSize(WebcamResolution.VGA.getSize()); webcam.open(); WebcamPanel webcampanel = new WebcamPanel(webcam); video2_panel.add(webcampanel); exitListener wl = new exitListener(camera,webcam); camera_window.addWindowListener(wl); // new Thread() { // public void run() { // while(true) { // ByteBuffer imagebyte = webcam.getImageBytes(); // } // } // }.start(); } }); window.add(camera); JButton text_color_button = new JButton(); text_color_button.setBackground(Color.black); text_color_button.setBounds(800,550,50,50); text_color_button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFrame color_choose_jf=new JFrame("Font-color"); color_choose_jf.setDefaultCloseOperation(2); color_choose_jf.setSize(100,140); JButton jb=(JButton)e.getSource(); Point p=jb.getLocationOnScreen(); double x=p.getX(); double y=p.getY(); color_choose_jf.setLocation((int)(x),(int)(y)-140); color_choose_jf.setLayout(new FlowLayout(FlowLayout.CENTER)); color_choose_jf.setResizable(false); Color[] colors=new Color[24]; for(int i=0;i<=23;i++) { colors[i]=new Color(1); } colors[0]=Color.black; colors[1]=Color.blue; colors[2]=Color.cyan; colors[3]=Color.DARK_GRAY; colors[4]=Color.gray; colors[5]=Color.green; colors[6]=Color.LIGHT_GRAY; colors[7]=Color.magenta; colors[8]=Color.orange; colors[9]=Color.pink; colors[10]=Color.red; colors[11]=Color.white; colors[12]=Color.yellow; JButton[] color_button=new JButton[24]; for(int i=0;i<=23;i++) { color_button[i]=new JButton(); color_button[i].addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color color=((JButton)e.getSource()).getBackground(); text_color_button.setBackground(color); } }); color_button[i].setBackground(colors[i]); color_button[i].setPreferredSize(new Dimension(20,20)); color_choose_jf.add(color_button[i]); } color_choose_jf.setVisible(true); } }); window.add(text_color_button); JButton font_button = new JButton(type_image); font_button.setBounds(850,550,50,50); window.add(font_button); //发送 JButton send = new JButton(submit_image); send.setBounds(900,550,100,50); send.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String msg =""; try { msg=textArea.getText()+'\n'; dsend.showText(msg); } catch (IOException e1) { e1.printStackTrace(); } Document docs = recordPanel.getDocument();//获得文本对象 try { AttributeSet attributeSet=new javax.swing.text.SimpleAttributeSet(); docs.insertString(docs.getLength(),new Date().toString()+" MINE "+msg,attributeSet);//对文本进行追加 } catch (BadLocationException e1) { e1.printStackTrace(); } }}); window.add(send); window.setVisible(true); dsend = new DataSender(recordPanel); //数据发送线程 // new Thread() { // public void run() { // try { // dsend = new DataSender(); // } catch (UnknownHostException e) { //
评论
    相关推荐
    • socket客户端.rar
      SOCKET 客户端 demo 。之前已经上传服务端demo
    • socket服务端.rar
      SOCKET 服务端demo 后续还有 客户端demo
    • Socket.zip
      实现TCP/UDP通信功能,UI界面实现,服务端与客户端本机对话
    • Socket.zip
      简单的Socket客户端和服务端,实现简单通讯
    • SuperSocket
      SuperSocket 是一个轻量级的可扩展的 Socket 开发框架,可用来构建一个服务器端 Socket 程序,而无需了解如何使用 Socket,如何维护Socket连接,Socket是如何工作的。该项目使用纯 C# 开发,易于扩展和集成到已有的...
    • socket通信基础
      socket通信基础;详细说明了socket的接口api使用
    • socket demo
      Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口。在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议族隐藏在Socket接口后面,对用户来说,一组简单的接口就是全部,让Socket去组织...
    • Socket
      Socket编程,基于tcp/ip协议的套节字编程
    • socket.rar
      java socket实现好友传递信息,传递文件,主体由客户端和服务端组成
    • socket.zip
      socket网络编程,客户端和服务端间通信,主要使用socket套接字