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

📄 impaneladminclient.java

📁 注:语音聊天部分还未完成
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.gamvan.club.users.im.admin;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.net.Socket;import java.util.Date;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JScrollPane;import javax.swing.JSplitPane;import javax.swing.JTextField;import javax.swing.SwingUtilities;import com.gamvan.club.users.im.tools.MyTextPane;public class IMPanelAdminClient extends JFrame {	/**	 * 管理员客户端的类	 */	private static final long serialVersionUID = 1L;		private JPanel jContentPane = null;	private JSplitPane mainSplit = null;	private JPanel jPanel = null;	private JButton login = null;	private JButton sendMeg = null;	private JButton logout = null;	private JTextField sendMegTextField = null;	private JScrollPane sendMegScrollPane = null;	private JScrollPane infoTextScrollPane = null;	private JScrollPane receiveMegScrollPane = null;	private MyTextPane receiveMeg = null;	private MyTextPane infoTextPane = null;	private JButton exit = null;	private JPanel otherPane = null;	private JTextField userName = null;	private JComboBox userOnlineList = null;		private Socket clientSocket = null;  //  @jve:decl-index=0:	private ObjectInputStream dataIn = null;	private ObjectOutputStream dataOut = null;  //  @jve:decl-index=0:	private AdminClientReceiveThread recevThread = null;	private JCheckBox statusCheckBox = null;	private JComboBox actionList = null;	private JPopupMenu popMenu = null;	private JMenuItem kickUser = null;	private JMenuItem warningUser = null;		private JButton messageNote = null;	private JButton hideNote = null;	private JPopupMenu popMenu1 = null;  //  @jve:decl-index=0:visual-constraint="20,55"	private JMenuItem clearText = null;		private Date date = null;	private MessageNote mn = null;	public String notes = "";  //  @jve:decl-index=0:	private String notes2 = "";	//  @jve:decl-index=0:visual-constraint=""	/**	 * 	初始化分割面板类	 */	private JSplitPane getMainSplit() {				if (mainSplit == null) {						mainSplit = new JSplitPane();			mainSplit.setLeftComponent(getInfoTextScrollPane());			mainSplit.setRightComponent(getReceiveMegScrollPane());					} 		return mainSplit;	}	/**	 * 	初始化buttonPane	 *	 */	private JPanel getJPanel() {		if (jPanel == null) {						jPanel = new JPanel();			jPanel.setLayout(new BoxLayout(getJPanel(), BoxLayout.X_AXIS));			jPanel.setPreferredSize(new Dimension(246, 30));			jPanel.setCursor(new java.awt.Cursor(					java.awt.Cursor.DEFAULT_CURSOR));			jPanel.add(getLogin(), null);			jPanel.add(getSendMeg(), null);			jPanel.add(getLogout(), null);			jPanel.add(getExit(), null);			jPanel.add(getSendMegScrollPane(), null);								}		return jPanel;	}	/**	 *		 * 	初始化登陆按钮并且修改其属性使其美观,并且添加事件监听器	 *	 */	private JButton getLogin() {		if (login == null) {						login = new JButton();			login.setText("登陆");			login.setMaximumSize(new java.awt.Dimension(60,60));			login.setMinimumSize(new java.awt.Dimension(60,60));			login.setName("login");			login.addActionListener(new java.awt.event.ActionListener() {				public void actionPerformed(java.awt.event.ActionEvent e) {										try {										//登陆到服务器						//connect("218.107.243.19",6544);						connect("192.168.1.111",6544);						messageNote.setEnabled(false);												hideNote.setEnabled(true);						login.setEnabled(false);						logout.setEnabled(true);						sendMeg.setEnabled(true);						exit.setEnabled(true);												//发送用户昵称						dataOut.writeObject(userName.getText()+ "(管理员)");						dataOut.flush();												recevThread.isStop = false;									} catch (IOException e1) {								e1.printStackTrace();						}							}						});				}		return login;	}	/**	 * 连接到服务器	 * 	 */	public void connect(String IP,int port){//与服务器端的连接程序	   try{		   //建立客户端套接字		   getClientSocket(IP,port);		   //得到套接字的数据输出流		   getDataOut();		   //得到套接字的数据输入流		   getDataIn();		   		   //创建客户接受线程	       recevThread = new AdminClientReceiveThread();	       recevThread.sendObject(clientSocket,dataOut,dataIn	                    ,receiveMeg,	                    userOnlineList,getSendMeg(),getMegNote(),	                    getSendMegTextField());	       recevThread.start();//启动监听线程	     }catch(IOException e){	        JOptionPane.showMessageDialog(this,"连接服务器出错!!",	                    "系统错误",JOptionPane.ERROR_MESSAGE);	        System.exit(0);	    }	               	}				/**	 * 	 * 	初始化发送信息按钮	 *	 */	private JButton getSendMeg() {		if (sendMeg == null) {			sendMeg = new JButton();						sendMeg.setText("发送");			sendMeg.setMaximumSize(new java.awt.Dimension(60,60));			sendMeg.setMinimumSize(new java.awt.Dimension(60,60));			sendMeg.setName("sendMeg");			sendMeg.addActionListener(new java.awt.event.ActionListener() {				public void actionPerformed(java.awt.event.ActionEvent e) {					if(clientSocket == null){						return;					}					if(!clientSocket.isClosed()){												login.setEnabled(false);						exit.setEnabled(true);						logout.setEnabled(true);						sendMeg.setEnabled(true);						sendMessage();//向所有用户发送消息												sendMegTextField.setText("");					}else{						return;					}				}			});		}		return sendMeg;	}	/**	 * 向其他客户端发送信息	 * */	public void sendMessage(){		//得到信息发送对象		String toSomebody = userOnlineList.getSelectedItem().toString();		String status = "";		//得到信息发送状态		if(statusCheckBox.isSelected()){			status = "<悄悄话>";		}		 String action = actionList.getSelectedItem().toString();         String message = sendMegTextField.getText();         if(clientSocket.isClosed()){             return;         }         if(message.equalsIgnoreCase("")){        	 JOptionPane.showMessageDialog(null,"抱歉,不能发送空消息",                     "系统警告",JOptionPane.WARNING_MESSAGE);        	         }else{        	 try{        		 dataOut.writeObject("聊天信息");//发送聊天信息标识        		 dataOut.flush();        	         		 dataOut.writeObject(toSomebody);//发送聊天信息对象        		 dataOut.flush();        	         		 dataOut.writeObject(getDate().toString());//发送信息发送时间        		 dataOut.flush();        	 	        		 dataOut.writeObject(status);//发送聊天信息状态        		 dataOut.flush();        	         		 dataOut.writeObject(action);//发送聊天信息表情        		 dataOut.flush();        	         		 dataOut.writeObject(message);//发送聊天信息内容        		 dataOut.flush();        	         		 dataOut.writeObject(Color.blue);        		 dataOut.flush();        	 }catch(IOException e){e.printStackTrace();}         }			}	/**	 * This method initializes loginOut		 * 		 * @return javax.swing.JButton		 */	private JButton getLogout() {//用户离线按钮		if (logout == null) {			logout = new JButton();			logout.setActionCommand(null);			logout.setText("离线");			logout.setName("logout");			logout.setMinimumSize(new java.awt.Dimension(60,60));			logout.setMaximumSize(new java.awt.Dimension(60,60));			logout.setBackground(null);			logout.addActionListener(new java.awt.event.ActionListener() {				public void actionPerformed(java.awt.event.ActionEvent e) {					if(clientSocket == null){						return;					}					if(clientSocket.isClosed()){						JOptionPane.showMessageDialog(null,"客户端套接字已经关闭!!" +                    			"请退出!!",                                "系统警告",JOptionPane.ERROR_MESSAGE);												recevThread.isStop = true;											}else if(!clientSocket.isClosed()){						try{														dataOut.writeObject("用户下线");//向服务器发送用户下线信息							dataOut.flush();														//停止接受线程							recevThread.isStop = true;							//设定各个按钮的状态							login.setEnabled(true);							sendMeg.setEnabled(false);							exit.setEnabled(true);							logout.setEnabled(false);							userOnlineList.removeAllItems();						}catch(IOException ex){							ex.printStackTrace();						}					}				}			});		}		return logout;	}	/**	 * This method initializes sendMegTextPane		 * 		 * @return javax.swing.JTextPane		 */	private JTextField getSendMegTextField() {		if (sendMegTextField == null) {			sendMegTextField = new JTextField();			sendMegTextField.setMinimumSize(new java.awt.Dimension(6,24));			sendMegTextField.addKeyListener(new java.awt.event.KeyAdapter() {				@Override				public void keyTyped(java.awt.event.KeyEvent e) {					if(e.getKeyChar() == (char)KeyEvent.VK_ENTER){						if(clientSocket == null){							return;						}						if(!clientSocket.isClosed()){														login.setEnabled(false);							exit.setEnabled(true);							logout.setEnabled(true);							sendMeg.setEnabled(true);														sendMessage();//向所有用户发送消息														sendMegTextField.setText("");						}else{							return;						}					}				}			});		}		return sendMegTextField;	}	/**	 * This method initializes sendMegScrollPane		 * 		 * @return javax.swing.JScrollPane		 */	private JScrollPane getSendMegScrollPane() {		if (sendMegScrollPane == null) {			sendMegScrollPane = new JScrollPane();			sendMegScrollPane.setViewportView(getSendMegTextField());			sendMegScrollPane.setWheelScrollingEnabled(true);		}		return sendMegScrollPane;	}	/**	 * This method initializes jTreeScrollPane		 * 		 * @return javax.swing.JScrollPane		 */	private JScrollPane getInfoTextScrollPane() {		if (infoTextScrollPane == null) {			infoTextScrollPane = new JScrollPane();			infoTextScrollPane.setViewportView(getInfoTextPane());		}		return infoTextScrollPane;	}	/**	 * This method initializes receiveMegScrollPane		 * 		 * @return javax.swing.JScrollPane		 */	private JScrollPane getReceiveMegScrollPane() {		if (receiveMegScrollPane == null) {			receiveMegScrollPane = new JScrollPane();			receiveMegScrollPane.setViewportView(getReceiveMeg());		}		return receiveMegScrollPane;	}	/**	 * This method initializes receiveMeg		 * 		 * @return javax.swing.JTextArea		 */	private MyTextPane getReceiveMeg() {		if (receiveMeg == null) {			receiveMeg = new MyTextPane();			receiveMeg.addMouseListener(new java.awt.event.MouseAdapter() {				@Override				public void mouseClicked(java.awt.event.MouseEvent e) {					if(e.getModifiers() == InputEvent.META_MASK){						getPopMenu1();						popMenu1.show(receiveMeg,e.getX(),e.getY());					}				}			});		}		return receiveMeg;	}	/**	 * This method initializes jTree		 * 		 * @return javax.swing.JTree		 */	private MyTextPane getInfoTextPane() {		if (infoTextPane == null) {			infoTextPane = new MyTextPane();                        infoTextPane.setForeground(Color.PINK);			infoTextPane.setText("恭喜你成为管理员,\n你可以警告或者踢出\n扰乱秩序的人!:)");			infoTextPane.setEditable(false);		}		

⌨️ 快捷键说明

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