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

📄 eq.java

📁 java Swing 和java DB数据库开发的类似QQ的聊天工具。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				if (e.isPopupTrigger())
					showMenu(e);
			}

			private void showMenu(MouseEvent e) {
				if (chatTree.getSelectionPaths() == null) {
					popupMenu.getComponent(0).setEnabled(false);
					popupMenu.getComponent(2).setEnabled(false);
					popupMenu.getComponent(3).setEnabled(false);
					popupMenu.getComponent(4).setEnabled(false);
					popupMenu.getComponent(5).setEnabled(false);
				} else {
					if (chatTree.getSelectionPaths().length < 2) {
						popupMenu.getComponent(3).setEnabled(false);
					} else {
						popupMenu.getComponent(3).setEnabled(true);
					}
					popupMenu.getComponent(0).setEnabled(true);
					popupMenu.getComponent(2).setEnabled(true);
					popupMenu.getComponent(4).setEnabled(true);
					popupMenu.getComponent(5).setEnabled(true);
				}
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}
	private void saveLocation() { // 保存主窗体位置的方法
		location = getBounds();
		dao.updateLocation(location);
	}
	protected JPopupMenu getPopupMenu() {// 创建用户弹出菜单
		if (popupMenu == null) {
			popupMenu = new JPopupMenu();
			popupMenu.setOpaque(false);
		}
		final JMenuItem rename = new JMenuItem();
		popupMenu.add(rename);
		rename.addActionListener(new RenameActionListener());
		rename.setText("更名");
		final JMenuItem addUser = new JMenuItem();
		addUser.addActionListener(new AddUserActionListener());
		popupMenu.add(addUser);
		addUser.setText("添加用户");
		final JMenuItem delUser = new JMenuItem();
		delUser.addActionListener(new delUserActionListener());
		popupMenu.add(delUser);
		delUser.setText("删除用户");
		final JMenuItem messagerGroupSend = new JMenuItem();
		messagerGroupSend
				.addActionListener(new messagerGroupSendActionListener());
		messagerGroupSend.setText("信使群发");
		popupMenu.add(messagerGroupSend);
		final JMenuItem accessComputerFolder = new JMenuItem("访问主机资源");
		accessComputerFolder.setActionCommand("computer");
		popupMenu.add(accessComputerFolder);
		accessComputerFolder
				.addActionListener(new accessFolderActionListener());
		final JMenuItem accessPublicFolder = new JMenuItem();
		popupMenu.add(accessPublicFolder);
		accessPublicFolder.setOpaque(false);
		accessPublicFolder.setText("访问公共程序");
		accessPublicFolder.setActionCommand("public");
		accessPublicFolder.addActionListener(new accessFolderActionListener());
		return popupMenu;
	}
	private void updateProject() { // 程序更新方法
		netFilePath = preferences.get("updatePath", "EQ.jar");
		if (netFilePath.equals("EQ.jar")) {
			pushMessage("未设置升级路径");
			return;
		}
		netFile = new File(netFilePath);
		localFile = new File(user_dir + File.separator + "EQ.jar");
		if (localFile != null && netFile != null && netFile.exists()
				&& localFile.exists()) {
			Date netDate = new Date(netFile.lastModified());
			Date localDate = new Date(localFile.lastModified());
			if (netDate.after(localDate)) {
				new Thread(new Runnable() {
					public void run() {
						try {
							Dialog frameUpdate = new UpdateFrame();
							frameUpdate.setVisible(true);
							Thread.sleep(2000);
							FileInputStream fis = new FileInputStream(netFile);
							FileOutputStream fout = new FileOutputStream(
									localFile);
							int len = fis.available();
							if (len > 0) {
								byte[] data = new byte[len];
								if (fis.read(data) > 0) {
									fout.write(data);
								}
							}
							fis.close();
							fout.close();
							frameUpdate.setVisible(false);
							frameUpdate = null;
							showMessageDialog("更新完毕,请重新启动程序。");
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				}).start();
			} else {
				showMessageDialog("已经是最新的程序了。");
			}
		}
	}

	private void checkPlacard() { // 检测公告信息方法
		String placardDir = preferences.get("placardPath", null);
		if (placardDir == null) {
			pushMessage("未设置公告路径");
			return;
		}
		File placard = new File(placardDir);
		try {
			if (placard.exists() && placard.isFile()) {
				StringBuilder placardStr = new StringBuilder();
				Scanner sc = new Scanner(new FileInputStream(placard));
				while (sc.hasNextLine()) {
					placardStr.append(sc.nextLine());
				}
				pushMessage(placardStr.toString());
			}
		} catch (FileNotFoundException e) {
			pushMessage("公告路径错误,或公告文件不存在");
		}
	}

	public void setStatic(String str) {// 设置状态栏信息
		if (stateLabel != null)
			stateLabel.setText(str);
	}

	private void pushMessage(String info) {// 堆压信息
		if (!messageStack.contains(info))
			messageStack.push(info);
	}

	private void showMessageDialog(String mess) {
		JOptionPane.showMessageDialog(this, mess);
	}

	private String showInputDialog(String str) { // 显示输入对话框
		String newName = JOptionPane.showInputDialog(this,
				"<html>输入<font color=red>" + str + "</font>的新名字</html>");
		return newName;
	}

	private class accessFolderActionListener implements ActionListener {// 访问资源
		public void actionPerformed(final ActionEvent e) {
			TreePath path = chatTree.getSelectionPath();
			if (path == null)
				return;
			DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
					.getLastPathComponent();
			User user = (User) node.getUserObject();
			String ip = "\\\\"+user.getIp();
			String command = e.getActionCommand();
			if (command.equals("computer")) {
				Resource.startFolder(ip);
			}
			if (command.equals("public")) {
				String serverPaeh = preferences.get("pubPath", null);
				if (serverPaeh == null) {
					pushMessage("未设置公共程序路径");
					return;
				}
				Resource.startFolder(serverPaeh);
			}
		}
	}

	private class RenameActionListener implements ActionListener {// 更名
		public void actionPerformed(final ActionEvent e) {
			TreePath path = chatTree.getSelectionPath();
			if (path == null)
				return;
			DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
					.getLastPathComponent();
			User user = (User) node.getUserObject();
			String newName = showInputDialog(user.getName());
			if (newName != null && !newName.isEmpty()) {
				user.setName(newName);
				dao.updateUser(user);
				DefaultTreeModel model = (DefaultTreeModel) chatTree.getModel();
				model.reload();
				chatTree.setSelectionPath(path);
				initUserInfoButton();
			}
		}
	}
	private class FrameWindowListener extends WindowAdapter {
		public void windowClosing(final WindowEvent e) {// 系统关闭事件
			setVisible(false);
		}
	}
	private class AddUserActionListener implements ActionListener {
		public void actionPerformed(final ActionEvent e) {// 添加用户
			String ip = JOptionPane.showInputDialog(EQ.this, "输入新用户IP地址");
			if (ip != null)
				chatTree.addUser(ip, "add");
		}
	}
	private class delUserActionListener implements ActionListener {
		public void actionPerformed(final ActionEvent e) {// 删除用户
			chatTree.delUser();
		}
	}
	private class messagerGroupSendActionListener implements ActionListener {// 信使群发
		public void actionPerformed(final ActionEvent e) {
			String message = JOptionPane.showInputDialog(EQ.this, "请输入群发信息",
					"信使群发", JOptionPane.INFORMATION_MESSAGE);
			if (message != null && !message.equals("")) {
				TreePath[] selectionPaths = chatTree.getSelectionPaths();
				Resource.sendGroupMessenger(selectionPaths, message);
			} else if (message != null && message.isEmpty()) {
				JOptionPane.showMessageDialog(EQ.this, "不能发送空信息!");
			}
		}
	}
	private void SystemTrayInitial() { // 系统栏初始化
		if (!SystemTray.isSupported()) // 判断当前系统是否支持系统栏
			return;
		try {
			String title = "EQ通讯软件";
			String company = "吉林省XXX科技有限公司";
			SystemTray sysTray = SystemTray.getSystemTray();
			Image image = Toolkit.getDefaultToolkit().getImage(
					EQ.class.getResource("/icons/sysTray.png"));// 系统栏图标
			trayicon = new TrayIcon(image, title + "\n" + company, createMenu());
			trayicon.setImageAutoSize(true);
			trayicon.addActionListener(new SysTrayActionListener());
			sysTray.add(trayicon);
			trayicon.displayMessage(title, company, MessageType.INFO);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private PopupMenu createMenu() { // 创建系统栏菜单的方法
		PopupMenu menu = new PopupMenu();
		MenuItem exitItem = new MenuItem("退出");
		exitItem.addActionListener(new ActionListener() { // 系统栏退出事件
					public void actionPerformed(ActionEvent e) {
						System.exit(0);
					}
				});
		MenuItem openItem = new MenuItem("打开");
		openItem.addActionListener(new ActionListener() {// 系统栏打开菜单项事件
					public void actionPerformed(ActionEvent e) {
						if (!isVisible()) {
							setVisible(true);
							toFront();
						} else
							toFront();
					}
				});

		// 系统栏的访问服务器菜单项事件
		MenuItem publicItem = new MenuItem("访问服务器");
		publicItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String serverPaeh = preferences.get("pubPath", null);
				if (serverPaeh == null) {
					pushMessage("未设置公共程序路径");
					return;
				}
				Resource.startFolder(serverPaeh);
			}
		});
		menu.add(publicItem);
		menu.add(openItem);
		menu.addSeparator();
		menu.add(exitItem);
		return menu;
	}
	class SysTrayActionListener implements ActionListener {// 系统栏双击事件
		public void actionPerformed(ActionEvent e) {
			setVisible(true);
			toFront();
		}
	}
}

⌨️ 快捷键说明

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