⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientgui.java

📁 实现简单的群聊功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * ClientGUI.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.edu.buaa.scse.liyi.network.client;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import cn.edu.buaa.scse.liyi.network.hibernate.bean.User;

/**
 *
 * @author  __USER__
 */
public class ClientGUI extends javax.swing.JFrame implements Runnable {

	private File file = null;
	private String sourcefilepath = null;
	private String userid, username;

	private Socket socket = null;
	private DataInputStream in = null;
	private DataOutputStream out = null;
	private Thread thread = null;
	private List<User> ulist = new ArrayList<User>();
	private String[] uarray = null;

	/** Creates new form ClientGUI */
	public ClientGUI() {
		initComponents();
	}

	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jPanel = new javax.swing.JPanel();
		idLabel = new javax.swing.JLabel();
		idTextField = new javax.swing.JTextField();
		nameLabel = new javax.swing.JLabel();
		nameTextField = new javax.swing.JTextField();
		submitButton = new javax.swing.JButton();
		exitButton = new javax.swing.JButton();
		infoLabel = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		chartTextArea = new javax.swing.JTextArea();
		jScrollPane2 = new javax.swing.JScrollPane();
		msgTextArea = new javax.swing.JTextArea();
		sendMsgButton = new javax.swing.JButton();
		jLabel0 = new javax.swing.JLabel();
		receiverComboBox = new javax.swing.JComboBox();
		fileTextField = new javax.swing.JTextField();
		sendFileButton = new javax.swing.JButton();
		jLabel1 = new javax.swing.JLabel();
		serverLabel = new javax.swing.JLabel();
		serverTextField = new javax.swing.JTextField();

		setTitle("Socket \u5ba2\u6237\u7aef");
		setDefaultCloseOperation(3);

		idLabel.setText("\u7528\u6237\u540d");

		nameLabel.setText("\u59d3\u540d");

		nameTextField.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				nameTextFieldActionPerformed(evt);
			}
		});

		submitButton.setText("\u786e\u5b9a");
		submitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				submitButtonActionPerformed(evt);
			}
		});

		exitButton.setText("\u9000\u51fa");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exitButtonActionPerformed(evt);
			}
		});

		chartTextArea.setColumns(20);
		chartTextArea.setRows(5);
		jScrollPane1.setViewportView(chartTextArea);

		msgTextArea.setColumns(20);
		msgTextArea.setRows(5);
		jScrollPane2.setViewportView(msgTextArea);

		sendMsgButton.setText("\u53d1\u9001\u6d88\u606f");
		sendMsgButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				sendMsgButtonActionPerformed(evt);
			}
		});

		jLabel0.setFont(new java.awt.Font("宋体", 0, 18));
		jLabel0.setText("\u5411");

		receiverComboBox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
		receiverComboBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				receiverComboBoxActionPerformed(evt);
			}
		});

		fileTextField.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				fileTextFieldActionPerformed(evt);
			}
		});
		fileTextField.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				fileTextFieldMouseClicked(evt);
			}
		});

		sendFileButton.setText("\u5f00\u59cb\u53d1\u9001");
		sendFileButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				sendFileButtonActionPerformed(evt);
			}
		});

		jLabel1.setFont(new java.awt.Font("宋体", 0, 18));
		jLabel1.setText("\u4f20\u9001\u6587\u4ef6");

		serverLabel.setText("\u670d\u52a1\u5668IP");

		serverTextField.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				serverTextFieldActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(
				jPanel);
		jPanel.setLayout(jPanelLayout);
		jPanelLayout
				.setHorizontalGroup(jPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																jPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				jPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								jScrollPane1,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								603,
																								Short.MAX_VALUE)
																						.addGroup(
																								jPanelLayout
																										.createSequentialGroup()
																										.addGroup(
																												jPanelLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING)
																														.addComponent(
																																idLabel)
																														.addComponent(
																																serverLabel))
																										.addGap(
																												4,
																												4,
																												4)
																										.addGroup(
																												jPanelLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING,
																																false)
																														.addGroup(
																																jPanelLayout
																																		.createSequentialGroup()
																																		.addComponent(
																																				idTextField,
																																				javax.swing.GroupLayout.PREFERRED_SIZE,
																																				88,
																																				javax.swing.GroupLayout.PREFERRED_SIZE)
																																		.addGap(
																																				17,
																																				17,
																																				17)
																																		.addComponent(
																																				nameLabel)
																																		.addPreferredGap(
																																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																		.addComponent(
																																				nameTextField,
																																				javax.swing.GroupLayout.PREFERRED_SIZE,
																																				86,
																																				javax.swing.GroupLayout.PREFERRED_SIZE))
																														.addComponent(
																																serverTextField))
																										.addGroup(
																												jPanelLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING)
																														.addGroup(
																																jPanelLayout
																																		.createSequentialGroup()
																																		.addGap(
																																				6,
																																				6,
																																				6)
																																		.addComponent(
																																				submitButton)
																																		.addPreferredGap(
																																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																		.addComponent(
																																				exitButton))
																														.addGroup(
																																jPanelLayout
																																		.createSequentialGroup()
																																		.addGap(
																																				123,
																																				123,
																																				123)
																																		.addComponent(
																																				infoLabel,
																																				javax.swing.GroupLayout.PREFERRED_SIZE,
																																				199,
																																				javax.swing.GroupLayout.PREFERRED_SIZE)))))
																		.addContainerGap())
														.addGroup(
																jPanelLayout
																		.createSequentialGroup()
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				jPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								jPanelLayout
																										.createSequentialGroup()
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												jScrollPane2,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												503,
																												Short.MAX_VALUE))
																						.addGroup(
																								jPanelLayout
																										.createSequentialGroup()
																										.addComponent(
																												jLabel0)
																										.addGap(
																												12,
																												12,
																												12)
																										.addComponent(
																												receiverComboBox,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												139,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												jLabel1)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																										.addComponent(
																												fileTextField,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												239,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				jPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								false)
																						.addComponent(
																								sendFileButton,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								sendMsgButton,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE))
																		.addGap(
																				23,
																				23,
																				23)))));
		jPanelLayout
				.setVerticalGroup(jPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -