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

📄 maingui.java

📁 企业级的即时通软件。。java语言写的 这是客户端部份。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package edu.sccp.chat.frame;






import java.awt.Component;
import java.awt.Container;
import java.awt.Image;

import java.awt.Font;
import java.awt.event.ActionEvent;
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.IOException;



import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;


import javax.swing.ButtonGroup;
import javax.swing.DebugGraphics;


import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingConstants;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import com.swtdesigner.SwingResourceManager;

import edu.sccp.chat.IconIntercalate.IconCellRenderer;
import edu.sccp.chat.IconIntercalate.IconData;
import edu.sccp.chat.action.ToServerProcess;
import edu.sccp.chat.jarClass.JarAllege;
import edu.sccp.chat.tools.FileStream;


public class MainGUI {

	private ButtonGroup buttonGroup = new ButtonGroup();
	/**
	 * @param args
	 */
	public static int CHANGE=0;//用来控制显示的信息窗体是否可为修改,0为不可修改,1为可修改
	private JFrame frame;
	private JLabel time;
	private JPanel panel_2;
	JPopupMenu popupMenu;
	JButton updateUserPwd;
	JButton adminchat;
	JPanel panel_4;
	JTree tree;
	protected IconCellRenderer m_renderer;
	public static JLabel label;//登录者名字
	public static JButton butpic;
	Vector userVector=null;
	Vector deptVector=null;
	public static ArrayList list;
	public String name;
	String dept;
	String quanxian;
	String id;
	JTextField idField;
	String pic;
	public static HashMap qun=new HashMap();
	public static HashMap siliao = new HashMap();//存放私聊对象
	SimpleDateFormat sim=new SimpleDateFormat("yyyy年MM月dd日");
	public static DefaultTreeModel m_model;//树模型
	public static DefaultMutableTreeNode top;//树的根接点
	public MainGUI(Vector vector)
	{
			userVector=(Vector) vector.get(0);//获取登陆用户的信息
			deptVector=(Vector) vector.get(1);//获取部门的信息
			list=(ArrayList) vector.get(2);//获取在线用户的列表
			name=(String) userVector.get(1);//获取用户的名字
			dept=(String) userVector.get(3);//获取用户所在部门
		    id=(String) userVector.get(0);
		    pic=(String) userVector.get(9);
		JarAllege.bai();
		initGUI();
	}
	private void initGUI()
	{
		frame=new JFrame("客户端主界面");
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(final WindowEvent e) {
				try {
					ToServerProcess.oos.writeObject("exit");
	 				ToServerProcess.oos.writeObject(userVector);
	 				ToServerProcess.toServer.close();
	 				ToServerProcess.ois.close();
	 				ToServerProcess.oos.close();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		frame.setIconImage(SwingResourceManager.getImage(MainGUI.class, "/edu/sccp/chat/image/icon.png"));
		Container contentPane=frame.getContentPane();
		contentPane.setLayout(null);

		butpic = new JButton();
		butpic.setIcon(SwingResourceManager.getIcon(MainGUI.class, (String) userVector.get(9)));
		butpic.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				//new UpdateSelfUser(userVector).showGUI();
				try {
					ToServerProcess.oos.writeObject("个人用户信息");
					ToServerProcess.oos.writeObject(id);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		butpic.setBounds(10, 10, 45, 39);
		frame.getContentPane().add(butpic);

		label = new JLabel();
		label.setFont(new Font("楷体_GB2312", Font.BOLD, 12));
		label.setText("登录者:"+userVector.get(1));
		label.setBounds(72, 28, 100, 21);
		frame.getContentPane().add(label);

		final JButton button = new JButton();
		button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/1.png"));
		button.setSelected(true);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				if(button.isSelected())
				{
					frame.setSize(247,100);
					button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/2.png"));
					panel_4.setBounds(45, 0, 51, 25);
					time.setBounds(102, 50, 131, 23);
					button.setSelected(false);
				}
				else
				{
					frame.setSize(247,445);
					button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/1.png"));
					panel_4.setBounds(0, 385, 51, 32);
					time.setBounds(102, 385, 131, 23);
					button.setSelected(true);
				}
			}
		});
		button.setBounds(177, 26, 54, 23);
		frame.getContentPane().add(button);

		final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
		tabbedPane.setTabPlacement(SwingConstants.LEFT);
		tabbedPane.setBounds(0, 73, 241, 306);
		tabbedPane.setFocusCycleRoot(true);
		tabbedPane.setDebugGraphicsOptions(DebugGraphics.NONE_OPTION);
		frame.getContentPane().add(tabbedPane);

		final JScrollPane scrollPane = new JScrollPane();
		tabbedPane.addTab("聊天", null, scrollPane, null);

		top = new DefaultMutableTreeNode(new IconData(
					new ImageIcon(System.getProperty("user.dir")+"/edu/sccp/chat/image/shu3.png"),new ImageIcon(System.getProperty("user.dir")+"/edu/sccp/chat/image/shu3.png"), "公司"));//主根
		
			for(int i=0;i<deptVector.size();i++)
			{
				top.add(new DefaultMutableTreeNode(new IconData(new ImageIcon(System.getProperty("user.dir")+"/edu/sccp/chat/image/shu4.png"),
						deptVector.get(i))));
			}
			for(int j=0;j<list.size();j++)
			{
				Vector user=(Vector) list.get(j);
				for(int i=0;i<MainGUI.top.getChildCount();i++){
					DefaultMutableTreeNode removenode = (DefaultMutableTreeNode)MainGUI.top.getChildAt(i);
					if(removenode.getUserObject().toString().equals((String)user.get(3)))
					{
						ImageIcon image1=new ImageIcon(System.getProperty("user.dir")+(String)user.get(9));//System.getProperty("user.dir")+
					    Image image= image1.getImage();
						Image smallImage=image.getScaledInstance(20,20, Image.SCALE_SMOOTH);
						ImageIcon smallIcon1=new ImageIcon(smallImage);
						removenode.add(new DefaultMutableTreeNode(new IconData(smallIcon1,(String)user.get(1))));
					}
				}
			}
			m_model=new DefaultTreeModel(top);
			tree = new JTree(m_model);
//			设置单选
			tree.getSelectionModel().setSelectionMode(
					TreeSelectionModel.SINGLE_TREE_SELECTION);
//			设置根把守
			tree.setShowsRootHandles(true);
			tree.setEditable(false);
//			设置图片
			m_renderer = new IconCellRenderer();
			tree.setCellRenderer(m_renderer);
			tree.addMouseListener(
					new MouseAdapter(){
						
						public void mouseClicked(MouseEvent e) {

							if (e.getClickCount() == 2) {
								TreePath selPath = tree
										.getPathForLocation(e.getX(), e.getY());
								if (selPath == null)
									return;
								DefaultMutableTreeNode node = (DefaultMutableTreeNode) (selPath
										.getLastPathComponent());
								if (node != null&& node.isLeaf()) {
									String name1=node.getUserObject().toString();
									String id1="";//对方ID
									String dept1="";//对方部门
									String pic1="";//对方头像
									for(int i=0;i<list.size();i++)
									{
										Vector v=(Vector)list.get(i);
										if(v.get(1).equals(name1.trim()))
										{
											
											id1=(String) v.get(0);
											dept1=(String)v.get(3);
											pic1=(String)v.get(9);
										}
									}
									SingleChatGUI single=(SingleChatGUI)MainGUI.siliao.get(id1);
									if(single==null)
									{//(对方头像,对方部门名字,对方名字,对方ID,自己的名字,自己部门名字,自己的头像,自己ID)
										SingleChatGUI sing=	new SingleChatGUI(pic1,dept1,name1,id1,name,dept,pic,id,true);
										siliao.put(id1.trim(),sing);
										sing.showGUI();
									}
									
								}
							}
						}
			});
			new Tree().start();
			scrollPane.setViewportView(tree);
		final JPanel panel = new JPanel();
		panel.setLayout(null);
		tabbedPane.addTab("查看", null, panel, null);

		final JRadioButton radioButton = new JRadioButton();
		radioButton.addItemListener(new ItemListener() {
			public void itemStateChanged(final ItemEvent e) {
				panel_2.setVisible(true);
			}
		});
		buttonGroup.add(radioButton);
		radioButton.setText("按ID号");
		radioButton.setBounds(21, 23, 74, 25);
		panel.add(radioButton);

		panel_2 = new JPanel();
		panel_2.setLayout(null);
		panel_2.setBounds(10, 54, 176, 143);
		panel_2.setVisible(false);
		panel.add(panel_2);

		final JLabel label_1 = new JLabel();
		label_1.setText("ID号:");
		label_1.setBounds(10, 10, 57, 16);
		panel_2.add(label_1);

		idField = new JTextField();
		idField.setBounds(40, 8, 104, 21);
		panel_2.add(idField);

		final JButton selectInfo = new JButton();
		selectInfo.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				
				try {
					ToServerProcess.oos.writeObject("查看用户信息");
					String id=idField.getText().trim();
					ToServerProcess.oos.writeObject(id);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		selectInfo.setText("查询");
		selectInfo.setBounds(32, 55, 95, 25);
		panel_2.add(selectInfo);

		final JButton selectAllUserInfo = new JButton();
		selectAllUserInfo.setText("查看所有用户");
		selectAllUserInfo.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				try {
					ToServerProcess.oos.writeObject("所有用户信息");
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		selectAllUserInfo.setBounds(42, 254, 111, 23);
		panel.add(selectAllUserInfo);

		final JButton showAdvertise = new JButton();
		showAdvertise.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				try {
					ToServerProcess.oos.writeObject("公司公告");
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		showAdvertise.setText("查看公告");
		showAdvertise.setBounds(42, 196, 111, 26);
		panel.add(showAdvertise);

		final JLabel label_3 = new JLabel();
		label_3.setText("查看用户信息");
		label_3.setBounds(21, 0, 90, 18);
		panel.add(label_3);

		final JButton showDept = new JButton();
		showDept.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				try {
					ToServerProcess.oos.writeObject("部门名称");
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		showDept.setText("查看部门信息");
		showDept.setBounds(42, 222, 111, 26);
		panel.add(showDept);

		final JPanel panel_1 = new JPanel();
		tabbedPane.addTab("管理", null, panel_1, null);
		panel_1.setLayout(null);

⌨️ 快捷键说明

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