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

📄 clientgui.java

📁 是个swing 写的好的通信程序,里面有数据库和原码,运行就可以了,希望好好的
💻 JAVA
字号:
package smoker.client;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import smoker.tools.*;

public class ClientGUI extends JFrame implements IClientGUI{
	
	public static final long serialVersionUID = 0;
	private SystemTray st;
	private TrayIcon ti;
	private JLabel labPhoto;
	private JLabel labUserID;
	private JLabel labNickName;
	private GridBagLayout gbl = new GridBagLayout();
	private GridBagConstraints gbc = new GridBagConstraints();
	private IClientCenter iClientCenter;
	private User currentUser;
	private Vector<User> userList;
	private Vector<Department> departmentList;
	private UserListManage userListManage;
	private ClientInfoGUI lookUser;

	public ClientGUI(IClientCenter iCCenter, User user) {
		this.iClientCenter = iCCenter;
		this.currentUser = user;
		lookUser = new ClientInfoGUI(this, currentUser, iClientCenter);
		this.setTitle("JICC2007");
		this.setSize(210, 675);
		this.setIconImage(Files.SERVER_ICON.getImage());
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		GUIManager.moveToTopRightCorner(this);
		userList = iClientCenter.getOnLineUser();
		departmentList = iClientCenter.getDptName();
		userListManage = new UserListManage(iClientCenter, userList,
				departmentList, currentUser);
		init();
		this.addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent ek) {

			}
		});
	}

	private void init() {
		JPanel container = (JPanel) this.getContentPane();
		container.setLayout(new BorderLayout());
		JPanel rootPanel = new JPanel();
		rootPanel.setLayout(new BorderLayout());
		labPhoto = GUIManager.createJLabel("");
		labPhoto.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		labUserID = GUIManager.createJLabel("");
		labUserID.setHorizontalTextPosition(JLabel.RIGHT);
		labNickName = GUIManager.createJLabel("");
		labNickName.setHorizontalTextPosition(JLabel.RIGHT);
		rootPanel.add(getTopPanel(), BorderLayout.NORTH);
		rootPanel.add(new JScrollPane(getCenterPanel()), BorderLayout.CENTER);
		rootPanel.add(getBottomPanel(), BorderLayout.SOUTH);
		labPhoto.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if(e.getButton() != MouseEvent.BUTTON1){
					return;
				}
					lookUser.setVisible(true);
			}
		});
		container.add(rootPanel, BorderLayout.CENTER);
		displayData(currentUser);
	}

	private JPanel getTopPanel() {
		JPanel tpPanel = new JPanel();
		tpPanel.setLayout(gbl);
		tpPanel.setBackground(new Color(218, 243, 253));
		gbc.anchor = GridBagConstraints.NORTH;
		GUIManager.setConstraints(gbl, gbc, 0, 0, 1, 2, 1, 1);
		tpPanel.add(labPhoto, gbc);

		gbc.fill = GridBagConstraints.HORIZONTAL;
		GUIManager.setConstraints(gbl, gbc, 1, 0, 2, 1, 1, 1);
		tpPanel.add(labUserID, gbc);
		GUIManager.setConstraints(gbl, gbc, 1, 1, 2, 1, 1, 1);
		tpPanel.add(labNickName, gbc);

		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		panel.add(tpPanel);
		return panel;
	}

	private JPanel getCenterPanel() {
		JPanel cenPanel = new JPanel();
		cenPanel.setLayout(new BorderLayout());
		cenPanel.setBackground(Color.white);
		cenPanel.add(userListManage.getUserListTree());
		return cenPanel;
	}

	private JPanel getBottomPanel() {
		JPanel botPanel = new JPanel();
		botPanel.setLayout(new BorderLayout());
		JLabel labIcon = new JLabel(Files.BOTTOM_ICON);
		botPanel.add(labIcon, BorderLayout.CENTER);
		return botPanel;
	}

	private void ExitToTray() {
		try {
			if (SystemTray.isSupported()) {// 判断当前平台是否支持系统托盘
				st = SystemTray.getSystemTray();
				Image icon = Toolkit.getDefaultToolkit().getImage("image/QQ.PNG");// 定义托盘图标的图片
				PopupMenu pm = new PopupMenu();
				MenuItem displayClient = new MenuItem("显示主窗体");
				displayClient.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						displayClient();
						st.remove(ti);
					}
				});
				MenuItem exitMenu = new MenuItem("退出系统");
				exitMenu.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						infromAbout();
						System.exit(0);
					}
				});
				pm.add(displayClient);
				pm.addSeparator();
				pm.add(exitMenu);
				if (ti == null) {
					ti = new TrayIcon(icon,
							"JICC:" + currentUser.getNickName(), pm);
				}
				ti.addMouseListener(new MouseAdapter() {
					public void mousePressed(MouseEvent e) {
						if (e.getClickCount() == 2) {
							displayClient();
							st.remove(ti);
						}
					}
				});
				st.add(ti);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void reciveMessage(ChatInfo chatInfo) {
		userListManage.handleReciveMsg(chatInfo);
	}

	public void addUserNode(User onLineUser) {
		userListManage.addUserNode(onLineUser);
	}

	public void removeUserNode(User offLineUser) {
		userListManage.removeUserNode(offLineUser);
	}

	private void infromAbout() {
		iClientCenter.offLineInfromAboutAllUser(currentUser);
		iClientCenter.offLineAndCloseSocket();
	}

	private void displayClient() {
		this.setVisible(true);
	}

	protected void processWindowEvent(WindowEvent evt) {
		if (evt.getID() == WindowEvent.WINDOW_CLOSING) {
			int ret = Msg.showSel("您确定要退出么?");
			if (ret == JOptionPane.YES_OPTION) {
				infromAbout();
				System.exit(0);
			}
		}
		if (evt.getID() == WindowEvent.WINDOW_ICONIFIED) {
			this.setVisible(false);
			ExitToTray();
		}
	}

	public void closeMe() {
		Msg.show("服务器已关闭,系统将要退出!");
		System.exit(0);
	}

	public void coerceOffLine() {
		Msg.show("由于某种原因,您被管理员强制离线了。\n系统即将退出!");
		infromAbout();
		System.exit(0);
	}

	public void updateResult(int result) {
		lookUser.onUpdateResult(result);
	}

	public void displayData(User user) {
		labPhoto.setIcon(user.getIcon());
		labUserID.setText("JICC: " + user.getLoginID());
		labNickName.setText("昵称: " + user.getNickName());
	}
}

⌨️ 快捷键说明

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