lirhyme преди 5 години
родител
ревизия
3f5268cad8

+ 0 - 0
chat/123_message.txt


+ 15 - 31
chat/src/AppServer.java

@@ -4,75 +4,59 @@ import java.net.*;
 import java.util.*;
 
 /**
- * 聊天系统服务器程序
+ * 聊天服务器
  */
-public class AppServer extends Thread
-{
+public class AppServer extends Thread {
 	private ServerSocket serverSocket;
 
 	private ServerFrame sFrame;
 
 	private static Vector userOnline = new Vector(1, 1);
-	
+
 	private static Vector v = new Vector(1, 1);
 
 	/**
 	 * 创建服务器 启动服务监听1001端口
 	 */
-	public AppServer()
-	{
+	public AppServer() {
 		sFrame = new ServerFrame();
-		try
-		{
+		try {
 			serverSocket = new ServerSocket(1001);
 			InetAddress address = InetAddress.getLocalHost();
 			sFrame.txtServerName.setText(address.getHostName());
 			sFrame.txtIP.setText(address.getHostAddress());
 			sFrame.txtPort.setText("1001");
-		} catch (IOException e)
-		{
+		} catch (IOException e) {
 			fail(e, "不能启动服务!");
 		}
 		sFrame.txtStatus.setText("已启动...");
 		this.start(); // 启动线程
 	}
 
-	/**
-	 * 退出服务器
-	 * 
-	 * @param e
-	 *                异常
-	 * @param str
-	 *                退出信息
-	 */
-	public static void fail(Exception e, String str)
-	{
+	// 退出服务器
+
+	public static void fail(Exception e, String str) {
 		System.out.println(str + " 。" + e);
 	}
 
 	/**
 	 * 监听客户的请求,当有用户请求时创建 Connection线程
 	 */
-	public void run()
-	{
-		try
-		{
-			while (true)
-			{
+	public void run() {
+		try {
+			while (true) {
 				Socket client = serverSocket.accept();
 				new Connection(sFrame, client, userOnline, v); // 支持多线程
 			}
-		} catch (IOException e)
-		{
+		} catch (IOException e) {
 			fail(e, "不能监听!");
 		}
 	}
 
-	/** 
+	/**
 	 * 启动服务器
 	 */
-	public static void main(String args[])
-	{
+	public static void main(String args[]) {
 		new AppServer();
 	}
 }

+ 4 - 3
chat/src/Chat.java

@@ -1,8 +1,9 @@
 
 import java.io.Serializable;
-
-public class Chat implements Serializable
-{
+/*
+ * ÁÄÌìÓû§
+ */
+public class Chat implements Serializable {
 
 	private static final long serialVersionUID = 4058485121419391969L;
 	/**

+ 0 - 14
chat/src/ChatClient.java

@@ -1,14 +0,0 @@
-
-
-public class ChatClient
-{
-
-	public ChatClient()
-	{
-	}
-
-	public static void main(String args[])
-	{
-		new Login();
-	}
-}

+ 4 - 24
chat/src/ChatRoom.java

@@ -8,7 +8,9 @@ import java.awt.event.*;
 import java.net.*;
 import java.io.*;
 import java.util.*;
-
+/*
+ * 聊天室
+ */
 public class ChatRoom extends Thread implements ActionListener {
 	static JFrame frmChat;
 
@@ -73,7 +75,6 @@ public class ChatRoom extends Thread implements ActionListener {
 			
 			@Override
 			public void mousePressed(MouseEvent e) {
-				// TODO Auto-generated method stub
 				
 			}
 			
@@ -93,12 +94,10 @@ public class ChatRoom extends Thread implements ActionListener {
 			
 			@Override
 			public void mouseClicked(MouseEvent e) {
-				// TODO Auto-generated method stub
 				
 			}
 		});
 		btnSave = new JButton("保存");
-		lblUserList = new JLabel("【在线用户列表】");
 		lblUserMessage = new JLabel("简单聊天室");
 		lblSendMessage = new JLabel("聊天内容:");
 		lblChatUser = new JLabel("你对:");
@@ -113,11 +112,7 @@ public class ChatRoom extends Thread implements ActionListener {
 		textLeft = new JTextPane();
 		textRight = new JTextPane();
 		cmbUser = new JComboBox(list);
-//		cmbUser.addItemListener(new ItemListener() {
-//			public void itemStateChanged(ItemEvent arg0) {
-//				freshHead();
-//			}
-//		});
+
 		chPrivateChat = new JCheckBox("私聊");
 		taUserMessage = new TextArea("", 300, 200,
 				TextArea.SCROLLBARS_VERTICAL_ONLY);// 只能向下滚动
@@ -133,8 +128,6 @@ public class ChatRoom extends Thread implements ActionListener {
 		btnSend.setBounds(630, 380, 80, 30);
 		
 	
-//		lblSendMessage.setBounds(210, 290, 60, 40);
-		lblUserList.setBounds(60, 0, 120, 40);
 		lblUserTotal.setBounds(180, 0, 60, 40);
 		lblCount.setBounds(430, 0, 60, 40);
 		lblCount1.setBounds(420, 0, 60, 40);
@@ -156,8 +149,6 @@ public class ChatRoom extends Thread implements ActionListener {
 		btnExit.setFont(fntDisp1);
 		btnSend.setFont(fntDisp1);
 		btnSave.setFont(fntDisp1);
-		lblUserList.setFont(fntDisp1);
-//		lblUserMessage.setFont(fntDisp1);
 		lblChatUser.setFont(fntDisp1);
 		lblSendMessage.setFont(fntDisp1);
 		lblUserTotal.setFont(fntDisp1);
@@ -169,9 +160,7 @@ public class ChatRoom extends Thread implements ActionListener {
 
 		lblUserMessage.setFont(new Font("Microsoft YaHei",0,17));
 		
-//		lblSendMessage.setForeground(Color.black);
 		btnExit.setForeground(Color.decode("#A8A8AA"));
-		lblUserList.setForeground(Color.decode("#606060"));
 		lblUserMessage.setForeground(Color.decode("#000000"));
 		lblChatUser.setForeground(Color.decode("#606060"));
 		lblUserTotal.setForeground(Color.decode("#606060"));
@@ -194,11 +183,7 @@ public class ChatRoom extends Thread implements ActionListener {
 		pnlChat.add(btnExit);
 		pnlChat.add(btnSend);
 		pnlChat.add(btnSave);
-//		pnlChat.add(lblUserList);
 		pnlChat.add(lblUserMessage);
-//		pnlChat.add(lblSendMessage);
-//		pnlChat.add(lblChatUser);
-//		pnlChat.add(lblUserTotal);
 		pnlChat.add(lblCount);
 		pnlChat.add(lblCount1);
 		pnlChat.add(lblCount2);
@@ -206,7 +191,6 @@ public class ChatRoom extends Thread implements ActionListener {
 		pnlChat.add(taUserMessage);
 		pnlChat.add(txtMessage);
 		pnlChat.add(textHead);
-//		pnlChat.add(textFoot);
 		pnlChat.add(textLeft);
 		pnlChat.add(textRight);
 		pnlChat.add(cmbUser);
@@ -515,10 +499,6 @@ public class ChatRoom extends Thread implements ActionListener {
 		headLabel.setIcon(new ImageIcon("images//" + head + ".png"));
 	}
 
-//	protected void freshHead() {
-//		String head = getUserHead(cmbUser.getSelectedItem().toString());
-//		headLabel.setIcon(new ImageIcon("images//" + head + ".png"));
-//	}
 
 	private String getUserHead(String selectedItem) {
 		String head = "oo";

+ 2 - 3
chat/src/Connection.java

@@ -10,9 +10,8 @@ import java.net.Socket;
 import java.util.Date;
 import java.util.Vector;
 
-/**
- * Title: HappyChat聊天系统服务器程序
- * @version 1.0
+/*
+ * 服务器与客户端
  */
 public class Connection extends Thread {
 	/**

+ 4 - 3
chat/src/Customer.java

@@ -1,7 +1,8 @@
+/*
+ * µÇ¼Óû§
+ */
+public class Customer extends Object implements java.io.Serializable {
 
-public class Customer extends Object implements java.io.Serializable
-{
-	
 	private static final long serialVersionUID = -9215977405584592618L;
 	/**
 	 * Óû§Ãû

+ 2 - 6
chat/src/Exit.java

@@ -1,15 +1,11 @@
 
-
-
 import java.io.Serializable;
 
-
-public class Exit implements Serializable
-{
+public class Exit implements Serializable {
 
 	private static final long serialVersionUID = -5267537916643834426L;
 	/**
 	 * Í˳öÕßÓû§Ãû
 	 */
-	public String exitname;	
+	public String exitname;
 }

+ 18 - 45
chat/src/Login.java

@@ -6,9 +6,8 @@ import java.awt.event.*;
 import java.net.*;
 import java.io.*;
 
-
 /**
- * 聊天系统登录程序
+ * 登录
  */
 public class Login extends JFrame implements ActionListener {
 
@@ -18,7 +17,7 @@ public class Login extends JFrame implements ActionListener {
 
 	private JButton btnLogin, btnRegister;
 
-	private JLabel  lblUserName, lblPassword, lblLogo;
+	private JLabel lblUserName, lblPassword, lblLogo;
 
 	private JTextField txtUserName, txtServer;
 
@@ -31,7 +30,6 @@ public class Login extends JFrame implements ActionListener {
 
 	private Toolkit toolkit = Toolkit.getDefaultToolkit();
 
-	
 	/**
 	 * 构造登陆窗体
 	 */
@@ -41,7 +39,6 @@ public class Login extends JFrame implements ActionListener {
 		pnlLogin = new JPanel();
 		this.getContentPane().add(pnlLogin);
 
-//		lblServer = new JLabel("服务器:");
 		lblUserName = new JLabel("用户名:");
 		lblPassword = new JLabel("密   码:");
 		txtServer = new JTextField(20);
@@ -49,22 +46,13 @@ public class Login extends JFrame implements ActionListener {
 		txtUserName = new JTextField(20);
 		pwdPassword = new JPasswordField(20);
 		btnLogin = new JButton("登录");
-//		btnLogin.setToolTipText("登录到服务器");
 		btnLogin.setMnemonic('L');
 		btnRegister = new JButton("注册");
-//		btnRegister.setToolTipText("注册新用户");
 		btnRegister.setMnemonic('R');
-//		btnExit = new JButton("退出");
-//		btnExit.setToolTipText("退出系统");
-//		btnExit.setMnemonic('X');
-		/***********************************************************************
-		 * 该布局采用手动布局 setBounds设置组件位置 * setFont设置字体、字型、字号 * setForeground设置文字的颜色 *
-		 * setBackground设置背景色 * setOpaque将背景设置为透明
-		 */
+
 		pnlLogin.setLayout(null); // 组件用手动布局
 		pnlLogin.setBackground(Color.decode("#f5f5f5"));
 
-//		lblServer.setBounds(60, 100, 100, 30);
 		txtServer.setBounds(150, 100, 120, 25);
 		lblUserName.setBounds(50, 155, 100, 30);
 		txtUserName.setBounds(100, 160, 120, 25);
@@ -72,32 +60,25 @@ public class Login extends JFrame implements ActionListener {
 		pwdPassword.setBounds(100, 190, 120, 25);
 		btnLogin.setBounds(40, 235, 200, 40);
 		btnRegister.setBounds(100, 325, 80, 25);
-//		btnExit.setBounds(210, 200, 80, 25);
 
 		Font fontstr = new Font("Microsoft YaHei", Font.PLAIN, 12);
-//		lblServer.setFont(fontstr);
 		txtServer.setFont(fontstr);
 		lblUserName.setFont(fontstr);
 		txtUserName.setFont(fontstr);
 		lblPassword.setFont(fontstr);
 		pwdPassword.setFont(fontstr);
-		btnLogin.setFont(new Font("Microsoft YaHei",0,15));
-		btnRegister.setFont(new Font("Microsoft YaHei",0,16));
-//		btnLogin.setFont(fontstr);
-//		btnRegister.setFont(fontstr);
-//		btnExit.setFont(fontstr);
-		
+		btnLogin.setFont(new Font("Microsoft YaHei", 0, 15));
+		btnRegister.setFont(new Font("Microsoft YaHei", 0, 16));
+
 		lblUserName.setForeground(Color.decode("#606060"));
 		lblPassword.setForeground(Color.decode("#606060"));
-		
+
 		btnLogin.setForeground(Color.decode("#FFFFFF"));
 		btnRegister.setForeground(Color.decode("#436895"));
 		btnLogin.setBackground(Color.decode("#1AAD19"));
 		btnRegister.setBackground(Color.decode("#f5f5f5"));
-//		btnExit.setBackground(Color.ORANGE);
 
 		txtServer.setVisible(false);
-//		pnlLogin.add(lblServer);
 		pnlLogin.add(txtServer);
 		pnlLogin.add(lblUserName);
 		pnlLogin.add(txtUserName);
@@ -105,28 +86,25 @@ public class Login extends JFrame implements ActionListener {
 		pnlLogin.add(pwdPassword);
 		pnlLogin.add(btnLogin);
 		pnlLogin.add(btnRegister);
-//		pnlLogin.add(btnExit);
 
 		// 设置背景图片
 		Icon logo1 = new ImageIcon("images\\boy01.png");
 		lblLogo = new JLabel(logo1);
 		lblLogo.setBounds(95, 20, 80, 80);
-		lblLogo.setSize(100,110);
+		lblLogo.setSize(100, 110);
 		pnlLogin.add(lblLogo);
 		// 设置登录窗口
 		setResizable(false);
 		setSize(280, 400);
 		setVisible(true);
 		scrnsize = toolkit.getScreenSize();
-		setLocation(scrnsize.width / 2 - this.getWidth() / 2, scrnsize.height
-				/ 2 - this.getHeight() / 2);
+		setLocation(scrnsize.width / 2 - this.getWidth() / 2, scrnsize.height / 2 - this.getHeight() / 2);
 		Image img = toolkit.getImage("images\\login01.png");
 		setIconImage(img);
 
-		// 三个按钮注册监听
+		//按钮注册监听
 		btnLogin.addActionListener(this);
 		btnRegister.addActionListener(this);
-//		btnExit.addActionListener(this);
 
 	} // 构造方法结束
 
@@ -138,8 +116,7 @@ public class Login extends JFrame implements ActionListener {
 		Object source = ae.getSource();
 		if (source.equals(btnLogin)) {
 			// 判断用户名和密码是否为空
-			if (txtUserName.getText().equals("")
-					|| pwdPassword.getText().equals("")) {
+			if (txtUserName.getText().equals("") || pwdPassword.getText().equals("")) {
 				JOptionPane op1 = new JOptionPane();
 				op1.showMessageDialog(null, "用户名或密码不能为空");
 			} else {
@@ -152,12 +129,9 @@ public class Login extends JFrame implements ActionListener {
 			this.dispose();
 			new Register(strServerIp);
 		}
-//		if (source == btnExit) {
-//			System.exit(0);
-//		}
-	} // actionPerformed()结束
+	}
 
-	/** 
+	/**
 	 * 登录事件响应方法
 	 */
 	@SuppressWarnings("deprecation")
@@ -170,13 +144,11 @@ public class Login extends JFrame implements ActionListener {
 			// 连接到服务器
 			Socket toServer;
 			toServer = new Socket(strServerIp, 1001);
-			ObjectOutputStream streamToServer = new ObjectOutputStream(toServer
-					.getOutputStream());
+			ObjectOutputStream streamToServer = new ObjectOutputStream(toServer.getOutputStream());
 			// 写客户详细资料到服务器socket
 			streamToServer.writeObject((Customer) data);
 			// 读来自服务器socket的登录状态
-			BufferedReader fromServer = new BufferedReader(
-					new InputStreamReader(toServer.getInputStream()));
+			BufferedReader fromServer = new BufferedReader(new InputStreamReader(toServer.getInputStream()));
 			String status = fromServer.readLine();
 			if (status.equals("登录成功")) {
 				new ChatRoom((String) data.custName, strServerIp);
@@ -201,14 +173,15 @@ public class Login extends JFrame implements ActionListener {
 		} catch (IOException e4) {
 			JOptionPane.showMessageDialog(null, "不能写入到指定服务器!");
 		}
-	} // login()结束
+	} 
 
 	/**
 	 * 启动登陆窗体
+	 * 
 	 * @param args
 	 */
 	public static void main(String args[]) {
 		new Login();
 	}
 
-} // Class Login结束
+} 

+ 3 - 1
chat/src/Message.java

@@ -1,7 +1,9 @@
 
 import java.io.Serializable;
 import java.util.Vector;
-
+/*
+ * ÁÄÌìÐÅÏ¢
+ */
 public class Message implements Serializable {
 
 	private static final long serialVersionUID = -3831507106408529855L;

+ 7 - 16
chat/src/Register.java

@@ -5,11 +5,9 @@ import java.awt.*;
 import java.awt.event.*;
 import java.net.*;
 import java.io.*;
-
-/*<p>Title:HappyChat聊天系统用户注册程序</p>
- *@version 1.0
+/*
+ * 注册
  */
-
 public class Register extends JFrame implements ActionListener {
 	private JComboBox comboBox;
 	private static final long serialVersionUID = 9019746127517522180L;
@@ -51,18 +49,11 @@ public class Register extends JFrame implements ActionListener {
 		btngGender = new ButtonGroup();
 		btnOk = new JButton("确定");
 		btnOk.setMnemonic('O');
-		// btnOk.setToolTipText("保存注册信息");
 		btnCancel = new JButton("返回");
 		btnCancel.setMnemonic('B');
-		// btnCancel.setToolTipText("返回登录窗口");
 		btnClear = new JButton("清空");
 		btnClear.setMnemonic('L');
-		// btnClear.setToolTipText("清空注册信息");
 
-		/*
-		 * 该布局采用手动布局 * setBounds设置组件位置 * setFont设置字体、字型、字号 *
-		 * setForeground设置文字的颜色 * setBackground设置背景色 * setOpaque将背景设置为透明
-		 */
 		pnlRegister.setLayout(null); // 组件用手动布局
 		pnlRegister.setBackground(Color.decode("#f5f5f5"));
 
@@ -137,11 +128,11 @@ public class Register extends JFrame implements ActionListener {
 		btngGender.add(rbtnMale);
 		btngGender.add(rbtnFemale);
 
-		// 设置背景图片
-		Icon logo = new ImageIcon("images\\register0.png");
-		logoPosition = new JLabel(logo);
-		logoPosition.setBounds(0, 0, 360, 78);
-		pnlRegister.add(logoPosition);
+		// // 设置背景图片
+		// Icon logo = new ImageIcon("images\\register0.png");
+		// logoPosition = new JLabel(logo);
+		// logoPosition.setBounds(0, 0, 360, 78);
+		// pnlRegister.add(logoPosition);
 
 		this.setSize(280, 405);
 		this.setVisible(true);

+ 9 - 6
chat/src/Register_Customer.java

@@ -1,7 +1,8 @@
+/*
+ * 注册用户
+ */
+public class Register_Customer extends Object implements java.io.Serializable {
 
-public class Register_Customer extends Object implements java.io.Serializable
-{
-	
 	private static final long serialVersionUID = 7116984729771538742L;
 	/**
 	 * 姓名
@@ -13,19 +14,21 @@ public class Register_Customer extends Object implements java.io.Serializable
 	public String custPassword;
 	/**
 	 * 年龄
-	 */	
+	 */
 	public String age;
 	/**
 	 * 性别
-	 */	
+	 */
 	public String sex;
 	/**
 	 * 电子邮件
 	 */
 	public String email;
-	 /**
+	/**
 	 * 头像文件名
 	 */
 	public String head;
 	
+	
+
 }

+ 223 - 228
chat/src/ServerFrame.java

@@ -8,7 +8,7 @@ import javax.swing.*;
 
 //////////*服务器窗口类*///////////////
 public class ServerFrame extends JFrame implements ActionListener {
-	public  JList list;
+	public JList list;
 	/**
 	 * 
 	 */
@@ -17,11 +17,9 @@ public class ServerFrame extends JFrame implements ActionListener {
 	// 服务器信息面板
 	JPanel pnlServer, pnlServerInfo;
 
-	JLabel lblStatus, lblNumber, lblMax, lblServerName, lblProtocol, lblIP,
-			lblPort, lblLog;
+	JLabel lblStatus, lblNumber, lblMax, lblServerName, lblProtocol, lblIP, lblPort, lblLog;
 
-	public JTextField txtStatus, txtNumber, txtMax, txtServerName, txtProtocol, txtIP,
-			txtPort;
+	public JTextField txtStatus, txtNumber, txtMax, txtServerName, txtProtocol, txtIP, txtPort;
 
 	JButton btnStop, btnSaveLog;
 
@@ -43,8 +41,8 @@ public class ServerFrame extends JFrame implements ActionListener {
 	JTextField txtNotice;
 
 	JButton btnSend, btnKick;
-	
-	public String serverMessage ="";
+
+	public String serverMessage = "";
 
 	public ServerFrame() {
 		// 服务器窗口
@@ -60,225 +58,223 @@ public class ServerFrame extends JFrame implements ActionListener {
 		if (fra.height > scr.height) {
 			fra.height = scr.height;
 		}
-		this.setLocation((scr.width - fra.width) / 2,
-				(scr.height - fra.height) / 2);
-
-		//服务器信息面板
-				pnlServer = new JPanel();
-				pnlServer.setLayout(null);
-				pnlServer.setBackground(new Color(245,245,245));
-				//左边表格信息
-				pnlServerInfo = new JPanel(new GridLayout(14,1));
-				pnlServerInfo.setBackground(Color.decode("#F5F5F5"));
-				pnlServerInfo.setFont(new Font("Microsoft YaHei",0,12));
-				pnlServerInfo.setBorder(BorderFactory.createCompoundBorder(
-						BorderFactory.createTitledBorder(""),
-						BorderFactory.createEmptyBorder(1,1,1,1)));
-				//表格列表
-				//第一行
-				lblStatus = new JLabel("当前状态:");
-				lblStatus.setForeground(Color.decode("#606060"));
-				lblStatus.setFont(new Font("Microsoft YaHei",0,12));
-				//第二行
-				txtStatus = new JTextField(10);
-				txtStatus.setBackground(Color.WHITE);
-				txtStatus.setForeground(Color.decode("#606060"));
-				txtStatus.setFont(new Font("Microsoft YaHei",0,12));
-				txtStatus.setEditable(false);
-				//第三行
-				lblNumber = new JLabel("当前在线人数:");
-				lblNumber.setForeground(Color.decode("#606060"));
-				lblNumber.setFont(new Font("Microsoft YaHei",0,12));
-				//第四行
-				txtNumber = new JTextField(10);
-				txtNumber.setBackground(Color.WHITE);
-				txtNumber.setForeground(Color.decode("#606060"));
-				txtNumber.setFont(new Font("Microsoft YaHei",0,12));
-				txtNumber.setEditable(false);
-				//第五行
-				lblMax = new JLabel("最多在线人数:");
-				lblMax.setForeground(Color.decode("#606060"));
-				lblMax.setFont(new Font("Microsoft YaHei",0,12));
-				//第六行
-				txtMax = new JTextField("50 人",10);
-				txtMax.setBackground(Color.WHITE);
-				txtMax.setForeground(Color.decode("#606060"));
-				txtMax.setFont(new Font("Microsoft YaHei",0,12));
-				txtMax.setEditable(false);
-				//第七行
-				lblServerName = new JLabel("服务器名称:");
-				lblServerName.setForeground(Color.decode("#606060"));
-				lblServerName.setFont(new Font("Microsoft YaHei",0,12));
-				//第八行
-				txtServerName = new JTextField(10);
-				txtServerName.setBackground(Color.WHITE);
-				txtServerName.setForeground(Color.decode("#606060"));
-				txtServerName.setFont(new Font("Microsoft YaHei",0,12));
-				txtServerName.setEditable(false);
-				//第九行
-				lblProtocol = new JLabel("访问协议:");
-				lblProtocol.setForeground(Color.decode("#606060"));
-				lblProtocol.setFont(new Font("Microsoft YaHei",0,12));
-				//第十行
-				txtProtocol = new JTextField("HTTP",10);
-				txtProtocol.setBackground(Color.WHITE);
-				txtProtocol.setForeground(Color.decode("#606060"));
-				txtProtocol.setFont(new Font("Microsoft YaHei",0,12));
-				txtProtocol.setEditable(false);
-				//第十一行
-				lblIP = new JLabel("服务器IP:");
-				lblIP.setForeground(Color.decode("#606060"));
-				lblIP.setFont(new Font("Microsoft YaHei",0,12));
-				//第十二行
-				txtIP = new JTextField(10);
-				txtIP.setBackground(Color.WHITE);
-				txtIP.setForeground(Color.decode("#606060"));
-				txtIP.setFont(new Font("Microsoft YaHei",0,12));
-				txtIP.setEditable(false);
-				//第十三行
-				lblPort = new JLabel("服务器端口:");
-				lblPort.setForeground(Color.decode("#606060"));
-				lblPort.setFont(new Font("Microsoft YaHei",0,12));
-				//第十四行
-				txtPort = new JTextField("8000",10);
-				txtPort.setBackground(Color.WHITE);
-				txtPort.setForeground(Color.decode("#606060"));
-				txtPort.setFont(new Font("Microsoft YaHei",0,12));
-				txtPort.setEditable(false);
-				//按钮
-				btnStop = new JButton("关闭服务器");
-				btnStop.addActionListener(new ActionListener() {
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						closeServer();
-					}
-				});
-				btnStop.setBackground(Color.decode("#F5F5F5"));
-				btnStop.setFont(new Font("Microsoft YaHei",0,12));
-				btnStop.setForeground(Color.decode("606060"));
-				//日志
-				lblLog = new JLabel("服务器日志");
-				lblLog.setFont(new Font("Microsoft YaHei",0,12));
-				lblLog.setForeground(Color.decode("#606060"));
-				taLog = new TextArea(20,50);
-				taLog.setFont(new Font("Microsoft YaHei",0,12));
-				
-				btnSaveLog = new JButton("保存日志");
-				btnSaveLog.addActionListener(new ActionListener() {
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						saveLog();
-					}
-				});
-				btnSaveLog.setBackground(Color.decode("#F5F5F5"));
-				btnSaveLog.setFont(new Font("Microsoft YaHei",0,12));
-				btnSaveLog.setForeground(Color.decode("606060"));
-				
-				pnlServerInfo.add(lblStatus);
-				pnlServerInfo.add(txtStatus);
-				pnlServerInfo.add(lblNumber);
-				pnlServerInfo.add(txtNumber);
-				pnlServerInfo.add(lblMax);
-				pnlServerInfo.add(txtMax);
-				pnlServerInfo.add(lblServerName);
-				pnlServerInfo.add(txtServerName);
-				pnlServerInfo.add(lblProtocol);
-				pnlServerInfo.add(txtProtocol);
-				pnlServerInfo.add(lblIP);
-				pnlServerInfo.add(txtIP);
-				pnlServerInfo.add(lblPort);
-				pnlServerInfo.add(txtPort);
-				
-				pnlServerInfo.setBounds(5,5,100,400);
-				lblLog.setBounds(110, 5, 100, 30);
-				taLog.setBounds(110,35,400,370);
-				btnStop.setBounds(150,410,120,30);
-				btnSaveLog.setBounds(270,410,120,30);
-				pnlServer.add(pnlServerInfo);
-				pnlServer.add(lblLog);
-				pnlServer.add(taLog);
-				pnlServer.add(btnStop);
-				pnlServer.add(btnSaveLog);
-				//用户面板
-				pnlUser = new JPanel();
-				pnlUser.setLayout(null);
-				pnlUser.setBackground(new Color(245,245,245));
-				pnlUser.setFont(new Font("Microsoft YaHei", 0, 12));
-				
-				lblMessage = new JLabel("用户消息");
-				lblMessage.setFont(new Font("Microsoft YaHei", 0, 12));
-				lblMessage.setForeground(Color.decode("#606060"));
-				taMessage = new TextArea(20, 20);
-				taMessage.setFont(new Font("Microsoft YaHei", 0, 12));
-				
-				lblNotice = new JLabel("通知:");
-				lblNotice.setFont(new Font("Microsoft YaHei", 0, 12));
-				lblNotice.setForeground(Color.decode("#606060"));
-				txtNotice = new JTextField(20);
-				txtNotice.setFont(new Font("Microsoft YaHei", 0, 12));
-				
-				btnSend = new JButton("发送");
-				btnSend.setBackground(Color.decode("#f5f5f5"));
-				btnSend.setFont(new Font("Microsoft YaHei", 0, 12));
-				btnSend.setForeground(Color.decode("#606060"));
-				btnSend.setEnabled(true);
-				btnSend.addActionListener(new ActionListener() {
-					public void actionPerformed(ActionEvent arg0) {
-						serverMessage();
-					}
-				});
-
-				lblUserCount = new JLabel("在线总人数 0 人");
-				lblUserCount.setFont(new Font("Microsoft YaHei", 0, 12));
-				lblUserCount.setForeground(Color.decode("#606060"));
-				
-				lblUser = new JLabel("在线用户列表");
-				lblUser.setFont(new Font("Microsoft YaHei", 0, 12));
-				lblUser.setForeground(Color.decode("#606060"));
-
-				lstUser = new JList();
-				lstUser.setFont(new Font("Microsoft YaHei", 0, 12));
-				lstUser.setVisibleRowCount(17);
-				lstUser.setFixedCellWidth(180);
-				lstUser.setFixedCellHeight(18);
-
-				spUser = new JScrollPane();
-				spUser.setBackground(Color.decode("#f5f5f5"));
-				spUser.setFont(new Font("Microsoft YaHei", 0, 12));
-				spUser.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
-				spUser.getViewport().setView(lstUser);
-
-				lblMessage.setBounds(5, 5, 100, 25);
-				taMessage.setBounds(5, 35, 300, 360);
-				lblUser.setBounds(310, 5, 100, 25);
-				spUser.setBounds(310, 35, 220, 360);
-				lblNotice.setBounds(5, 410, 40, 25);
-				txtNotice.setBounds(50, 410, 160, 25);
-				btnSend.setBounds(210, 410, 80, 25);
-				lblUserCount.setBounds(320, 410, 100, 25);
-
-				pnlUser.add(lblMessage);
-				pnlUser.add(taMessage);
-				pnlUser.add(lblUser);
-				pnlUser.add(spUser);
-
-				list = new JList<>();
-				list.setListData(new String[] { "" });
-				spUser.setViewportView(list);
-				pnlUser.add(lblNotice);
-				pnlUser.add(txtNotice);
-				pnlUser.add(btnSend);
-				pnlUser.add(lblUserCount);
-				//主标签面板
-				tpServer=new JTabbedPane(JTabbedPane.LEFT);
-				tpServer.setBackground(Color.decode("#f5f5f5"));
-				tpServer.setFont(new Font("Microsoft YaHei", 0, 12));
-				tpServer.add("服务器管理", pnlServer);
-				tpServer.add("用户信息管理", pnlUser);
-				this.getContentPane().add(tpServer);
-				setVisible(true);
-				
+		this.setLocation((scr.width - fra.width) / 2, (scr.height - fra.height) / 2);
+
+		// 服务器信息面板
+		pnlServer = new JPanel();
+		pnlServer.setLayout(null);
+		pnlServer.setBackground(new Color(245, 245, 245));
+		// 左边表格信息
+		pnlServerInfo = new JPanel(new GridLayout(14, 1));
+		pnlServerInfo.setBackground(Color.decode("#F5F5F5"));
+		pnlServerInfo.setFont(new Font("Microsoft YaHei", 0, 12));
+		pnlServerInfo.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),
+				BorderFactory.createEmptyBorder(1, 1, 1, 1)));
+		// 表格列表
+		// 第一行
+		lblStatus = new JLabel("当前状态:");
+		lblStatus.setForeground(Color.decode("#606060"));
+		lblStatus.setFont(new Font("Microsoft YaHei", 0, 12));
+		// 第二行
+		txtStatus = new JTextField(10);
+		txtStatus.setBackground(Color.WHITE);
+		txtStatus.setForeground(Color.decode("#606060"));
+		txtStatus.setFont(new Font("Microsoft YaHei", 0, 12));
+		txtStatus.setEditable(false);
+		// 第三行
+		lblNumber = new JLabel("当前在线人数:");
+		lblNumber.setForeground(Color.decode("#606060"));
+		lblNumber.setFont(new Font("Microsoft YaHei", 0, 12));
+		// 第四行
+		txtNumber = new JTextField(10);
+		txtNumber.setBackground(Color.WHITE);
+		txtNumber.setForeground(Color.decode("#606060"));
+		txtNumber.setFont(new Font("Microsoft YaHei", 0, 12));
+		txtNumber.setEditable(false);
+		// 第五行
+		lblMax = new JLabel("最多在线人数:");
+		lblMax.setForeground(Color.decode("#606060"));
+		lblMax.setFont(new Font("Microsoft YaHei", 0, 12));
+		// 第六行
+		txtMax = new JTextField("50 人", 10);
+		txtMax.setBackground(Color.WHITE);
+		txtMax.setForeground(Color.decode("#606060"));
+		txtMax.setFont(new Font("Microsoft YaHei", 0, 12));
+		txtMax.setEditable(false);
+		// 第七行
+		lblServerName = new JLabel("服务器名称:");
+		lblServerName.setForeground(Color.decode("#606060"));
+		lblServerName.setFont(new Font("Microsoft YaHei", 0, 12));
+		// 第八行
+		txtServerName = new JTextField(10);
+		txtServerName.setBackground(Color.WHITE);
+		txtServerName.setForeground(Color.decode("#606060"));
+		txtServerName.setFont(new Font("Microsoft YaHei", 0, 12));
+		txtServerName.setEditable(false);
+		// 第九行
+		lblProtocol = new JLabel("访问协议:");
+		lblProtocol.setForeground(Color.decode("#606060"));
+		lblProtocol.setFont(new Font("Microsoft YaHei", 0, 12));
+		// 第十行
+		txtProtocol = new JTextField("HTTP", 10);
+		txtProtocol.setBackground(Color.WHITE);
+		txtProtocol.setForeground(Color.decode("#606060"));
+		txtProtocol.setFont(new Font("Microsoft YaHei", 0, 12));
+		txtProtocol.setEditable(false);
+		// 第十一行
+		lblIP = new JLabel("服务器IP:");
+		lblIP.setForeground(Color.decode("#606060"));
+		lblIP.setFont(new Font("Microsoft YaHei", 0, 12));
+		// 第十二行
+		txtIP = new JTextField(10);
+		txtIP.setBackground(Color.WHITE);
+		txtIP.setForeground(Color.decode("#606060"));
+		txtIP.setFont(new Font("Microsoft YaHei", 0, 12));
+		txtIP.setEditable(false);
+		// 第十三行
+		lblPort = new JLabel("服务器端口:");
+		lblPort.setForeground(Color.decode("#606060"));
+		lblPort.setFont(new Font("Microsoft YaHei", 0, 12));
+		// 第十四行
+		txtPort = new JTextField("8000", 10);
+		txtPort.setBackground(Color.WHITE);
+		txtPort.setForeground(Color.decode("#606060"));
+		txtPort.setFont(new Font("Microsoft YaHei", 0, 12));
+		txtPort.setEditable(false);
+		// 按钮
+		btnStop = new JButton("关闭服务器");
+		btnStop.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				closeServer();
+			}
+		});
+		btnStop.setBackground(Color.decode("#F5F5F5"));
+		btnStop.setFont(new Font("Microsoft YaHei", 0, 12));
+		btnStop.setForeground(Color.decode("606060"));
+		// 日志
+		lblLog = new JLabel("服务器日志");
+		lblLog.setFont(new Font("Microsoft YaHei", 0, 12));
+		lblLog.setForeground(Color.decode("#606060"));
+		taLog = new TextArea(20, 50);
+		taLog.setFont(new Font("Microsoft YaHei", 0, 12));
+
+		btnSaveLog = new JButton("保存日志");
+		btnSaveLog.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				saveLog();
+			}
+		});
+		btnSaveLog.setBackground(Color.decode("#F5F5F5"));
+		btnSaveLog.setFont(new Font("Microsoft YaHei", 0, 12));
+		btnSaveLog.setForeground(Color.decode("606060"));
+
+		pnlServerInfo.add(lblStatus);
+		pnlServerInfo.add(txtStatus);
+		pnlServerInfo.add(lblNumber);
+		pnlServerInfo.add(txtNumber);
+		pnlServerInfo.add(lblMax);
+		pnlServerInfo.add(txtMax);
+		pnlServerInfo.add(lblServerName);
+		pnlServerInfo.add(txtServerName);
+		pnlServerInfo.add(lblProtocol);
+		pnlServerInfo.add(txtProtocol);
+		pnlServerInfo.add(lblIP);
+		pnlServerInfo.add(txtIP);
+		pnlServerInfo.add(lblPort);
+		pnlServerInfo.add(txtPort);
+
+		pnlServerInfo.setBounds(5, 5, 100, 400);
+		lblLog.setBounds(110, 5, 100, 30);
+		taLog.setBounds(110, 35, 400, 370);
+		btnStop.setBounds(150, 410, 120, 30);
+		btnSaveLog.setBounds(270, 410, 120, 30);
+		pnlServer.add(pnlServerInfo);
+		pnlServer.add(lblLog);
+		pnlServer.add(taLog);
+		pnlServer.add(btnStop);
+		pnlServer.add(btnSaveLog);
+		// 用户面板
+		pnlUser = new JPanel();
+		pnlUser.setLayout(null);
+		pnlUser.setBackground(new Color(245, 245, 245));
+		pnlUser.setFont(new Font("Microsoft YaHei", 0, 12));
+
+		lblMessage = new JLabel("用户消息");
+		lblMessage.setFont(new Font("Microsoft YaHei", 0, 12));
+		lblMessage.setForeground(Color.decode("#606060"));
+		taMessage = new TextArea(20, 20);
+		taMessage.setFont(new Font("Microsoft YaHei", 0, 12));
+
+		lblNotice = new JLabel("通知:");
+		lblNotice.setFont(new Font("Microsoft YaHei", 0, 12));
+		lblNotice.setForeground(Color.decode("#606060"));
+		txtNotice = new JTextField(20);
+		txtNotice.setFont(new Font("Microsoft YaHei", 0, 12));
+
+		btnSend = new JButton("发送");
+		btnSend.setBackground(Color.decode("#f5f5f5"));
+		btnSend.setFont(new Font("Microsoft YaHei", 0, 12));
+		btnSend.setForeground(Color.decode("#606060"));
+		btnSend.setEnabled(true);
+		btnSend.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				serverMessage();
 			}
+		});
+
+		lblUserCount = new JLabel("在线总人数 0 人");
+		lblUserCount.setFont(new Font("Microsoft YaHei", 0, 12));
+		lblUserCount.setForeground(Color.decode("#606060"));
+
+		lblUser = new JLabel("在线用户列表");
+		lblUser.setFont(new Font("Microsoft YaHei", 0, 12));
+		lblUser.setForeground(Color.decode("#606060"));
+
+		lstUser = new JList();
+		lstUser.setFont(new Font("Microsoft YaHei", 0, 12));
+		lstUser.setVisibleRowCount(17);
+		lstUser.setFixedCellWidth(180);
+		lstUser.setFixedCellHeight(18);
+
+		spUser = new JScrollPane();
+		spUser.setBackground(Color.decode("#f5f5f5"));
+		spUser.setFont(new Font("Microsoft YaHei", 0, 12));
+		spUser.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
+		spUser.getViewport().setView(lstUser);
+
+		lblMessage.setBounds(5, 5, 100, 25);
+		taMessage.setBounds(5, 35, 300, 360);
+		lblUser.setBounds(310, 5, 100, 25);
+		spUser.setBounds(310, 35, 220, 360);
+		lblNotice.setBounds(5, 410, 40, 25);
+		txtNotice.setBounds(50, 410, 160, 25);
+		btnSend.setBounds(210, 410, 80, 25);
+		lblUserCount.setBounds(320, 410, 100, 25);
+
+		pnlUser.add(lblMessage);
+		pnlUser.add(taMessage);
+		pnlUser.add(lblUser);
+		pnlUser.add(spUser);
+
+		list = new JList<>();
+		list.setListData(new String[] { "" });
+		spUser.setViewportView(list);
+		pnlUser.add(lblNotice);
+		pnlUser.add(txtNotice);
+		pnlUser.add(btnSend);
+		pnlUser.add(lblUserCount);
+		// 主标签面板
+		tpServer = new JTabbedPane(JTabbedPane.LEFT);
+		tpServer.setBackground(Color.decode("#f5f5f5"));
+		tpServer.setFont(new Font("Microsoft YaHei", 0, 12));
+		tpServer.add("服务器管理", pnlServer);
+		tpServer.add("用户信息管理", pnlUser);
+		this.getContentPane().add(tpServer);
+		setVisible(true);
+
+	}
 
 	protected void serverMessage() {
 		this.serverMessage = txtNotice.getText();
@@ -291,8 +287,7 @@ public class ServerFrame extends JFrame implements ActionListener {
 
 	protected void saveLog() {
 		try {
-			FileOutputStream fileoutput = new FileOutputStream("log.txt",
-					true);
+			FileOutputStream fileoutput = new FileOutputStream("log.txt", true);
 			String temp = taMessage.getText();
 			fileoutput.write(temp.getBytes());
 			fileoutput.close();
@@ -304,7 +299,7 @@ public class ServerFrame extends JFrame implements ActionListener {
 
 	private void log(String string) {
 		String newta = taMessage.getText();
-		newta += ("\n"+string);
+		newta += ("\n" + string);
 		taMessage.setText(newta);
 	}
 

BIN
chat/user.txt