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

📄 eq.java

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

	private JScrollPane createSysToolPanel() {// 系统工具面板
		JPanel sysToolPanel = new JPanel(); // 系统工具面板
		sysToolPanel.setLayout(new BorderLayout());
		JScrollPane sysToolScrollPanel = new JScrollPane();
		sysToolScrollPanel
				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		sysToolScrollPanel.setBorder(new EmptyBorder(0, 0, 0, 0));
		sysToolScrollPanel.setViewportView(sysToolPanel);
		sysToolPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
		JPanel interfacePanel = new JPanel();
		sysToolPanel.add(interfacePanel, BorderLayout.NORTH);
		interfacePanel.setLayout(new BorderLayout());
		interfacePanel.setBorder(new TitledBorder("界面选择-再次启动生效"));
		faceList = new JList(new String[]{"当前系统", "java默认"});
		interfacePanel.add(faceList);
		faceList.setBorder(new BevelBorder(BevelBorder.LOWERED));
		final JPanel interfaceSubPanel = new JPanel();
		interfaceSubPanel.setLayout(new FlowLayout());
		interfacePanel.add(interfaceSubPanel, BorderLayout.SOUTH);
		selectInterfaceOKButton = new JButton("确定");
		selectInterfaceOKButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				preferences.put("lookAndFeel", faceList.getSelectedValue()
						.toString());
				JOptionPane.showMessageDialog(EQ.this, "重新运行本软件后生效");
			}
		});
		interfaceSubPanel.add(selectInterfaceOKButton);

		JPanel searchUserPanel = new JPanel(); // 用户搜索面板
		sysToolPanel.add(searchUserPanel);
		searchUserPanel.setLayout(new BorderLayout());
		final JPanel searchControlPanel = new JPanel();
		searchControlPanel.setLayout(new GridLayout(0, 1));
		searchUserPanel.add(searchControlPanel, BorderLayout.SOUTH);
		final JList searchUserList = new JList(new String[]{"检测用户列表"});// 新添加用户列表
		final JScrollPane scrollPane_2 = new JScrollPane(searchUserList);
		scrollPane_2.setDoubleBuffered(true);
		searchUserPanel.add(scrollPane_2);
		searchUserList.setBorder(new BevelBorder(BevelBorder.LOWERED));
		searchUserButton = new JToggleButton();
		searchUserButton.setText("搜索新用户");
		searchUserButton.addActionListener(new SearchUserActionListener(searchUserList));
		searchControlPanel.add(progressBar);
		searchControlPanel.add(searchUserButton);
		searchUserPanel.setBorder(new TitledBorder("搜索用户"));

		final JPanel sysUpdatePanel = new JPanel();
		sysUpdatePanel.setOpaque(false);
		sysUpdatePanel.setLayout(new GridBagLayout());
		sysUpdatePanel.setBorder(new TitledBorder("系统操作"));
		sysToolPanel.add(sysUpdatePanel, BorderLayout.SOUTH);
		final JButton sysUpdateButton = new JButton("系统更新");
		final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
		gridBagConstraints_1.gridx = 0;
		gridBagConstraints_1.gridy = 0;
		sysUpdatePanel.add(sysUpdateButton, gridBagConstraints_1);
		sysUpdateButton.addActionListener(new SysUpdateListener());// 添加系统更新事件
		final JLabel updateLabel = new JLabel("最近更新:");
		final GridBagConstraints updateLabelLayout = new GridBagConstraints();
		updateLabelLayout.gridy = 1;
		updateLabelLayout.gridx = 0;
		sysUpdatePanel.add(updateLabel, updateLabelLayout);
		final JLabel updateDateLabel = new JLabel();// 程序更新日期标签
		Date date = new Date(localFile.lastModified());
		String dateStr = String.format("%tF %<tr", date);
		updateDateLabel.setText(dateStr);
		final GridBagConstraints updateDateLayout = new GridBagConstraints();
		updateDateLayout.gridy = 2;
		updateDateLayout.gridx = 0;
		sysUpdatePanel.add(updateDateLabel, updateDateLayout);
		final JLabel updateStaticLabel = new JLabel("更新状态:");
		final GridBagConstraints updateStaticLayout = new GridBagConstraints();
		updateStaticLayout.gridy = 3;
		updateStaticLayout.gridx = 0;
		sysUpdatePanel.add(updateStaticLabel, updateStaticLayout);
		final JLabel updateInfoLabel = new JLabel();// 版本信息标签
		checkSysInfo(updateInfoLabel);// 调用检测版本更新的方法
		final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
		gridBagConstraints_5.gridy = 4;
		gridBagConstraints_5.gridx = 0;
		sysUpdatePanel.add(updateInfoLabel, gridBagConstraints_5);
		JPanel statePanel = new JPanel();
		add(statePanel, BorderLayout.SOUTH);
		statePanel.setLayout(new BorderLayout());
		statePanel.add(stateLabel);
		stateLabel.setText("总人数:" + chatTree.getRowCount());
		return sysToolScrollPanel;
	}

	private void initUserInfoButton() {// 初始化用户信息按钮
		try {
			String ip = InetAddress.getLocalHost().getHostAddress();
			User user = dao.getUser(ip);
			userInfoButton.setIcon(user.getIconImg());
			userInfoButton.setText(user.getName());
			userInfoButton.setIconTextGap(JLabel.RIGHT);
			userInfoButton.setToolTipText(user.getTipText());
			userInfoButton.getParent().doLayout();
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
	}

	private void showMessageBar() { // 显示公告信息按钮的线程
		new Thread(new Runnable() {
			public void run() {
				while (true) {
					if (!messageStack.empty()) {
						try {
							messageAlertButton.setIcon(messageAlertNullIcon);
							messageAlertButton.setPreferredSize(new Dimension(
									20, 20));
							Thread.sleep(500);
							messageAlertButton.setIcon(messageAlertIcon);
							Thread.sleep(500);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					} else {
						try {
							Thread.sleep(3000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}
			}
		}).start();
	}

	private void checkSysInfo(final JLabel updateInfo) {// 检测版本更新
		new Thread(new Runnable() {
			public void run() {
				String info = "";
				while (true) {
					try {
						netFilePath = preferences.get("updatePath", "EQ.jar");
						if (netFilePath.equals("EQ.jar")) {
							info = "<html><center><font color=red><b>无法登录</b><br>未设置升级路径</font></center></html>";
							updateInfo.setText(info);
							continue;
						}
						netFile = new File(netFilePath);
						if (netFile.exists()) {
							Date netDate = new Date(netFile.lastModified());
							if (!localFile.exists())
								info = "<html><font color=blue>本地程序位置出错!</font></html>";
							else {
								Date localDate = new Date(localFile
										.lastModified());
								if (netDate.after(localDate)) {
									info = "<html><font color=blue>网络上有最新程序!</font></html>";
									pushMessage(info);
								} else
									info = "<html><font color=green>现在是最新程序!</font></html>";
							}
						} else {
							info = "<html><center><font color=red><b>无法访问</b><br>升级路径</font></center></html>";
						}
						updateInfo.setText(info);
						Thread.sleep(5 * 1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}
	class SearchUserActionListener implements ActionListener {
		private final JList list;
		SearchUserActionListener(JList list) {
			this.list = list;
		}
		public void actionPerformed(ActionEvent e) {
			if (searchUserButton.isSelected()) {
				searchUserButton.setText("停止搜索");
				new Thread(new Runnable() {
					public void run() {
						Resource.searchUsers(chatTree, progressBar,
								list, searchUserButton);
					}
				}).start();
			} else
				searchUserButton.setText("搜索新用户");
		}
	}

	class SysSetPanelOKListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			String command = e.getActionCommand();
			if (command.equals("sysOK")) {
				String updatePath = updatePathTField.getText();
				String placardPath = placardPathTField.getText();
				String pubPath = pubPathTField.getText();
				preferences.put("updatePath", updatePath); // 设置系统升级路径
				preferences.put("placardPath", placardPath);// 设置系统公告路径
				preferences.put("pubPath", pubPath); // 设置公共程序路径
				JOptionPane.showMessageDialog(EQ.this, "系统设置保存完毕");
			}
			if (command.equals("loginOK")) {
				String username = userNameTField.getText();
				String password = new String(passwordTField.getPassword());
				preferences.put("username", username); // 设置系统升级路径
				preferences.put("password", password);// 设置系统公告路径
				JOptionPane.showMessageDialog(EQ.this, "登录设置保存完毕");
			}
			if (command.equals("ipOK")) {
				String ipStart = ipStartTField.getText();
				String ipEnd = ipEndTField.getText();
				try {
					InetAddress.getByName(ipStart);
					InetAddress.getByName(ipEnd);
				} catch (UnknownHostException e1) {
					JOptionPane.showMessageDialog(EQ.this, "IP地址格式错误");
					return;
				}
				preferences.put("ipStart", ipStart); // 设置系统升级路径
				preferences.put("ipEnd", ipEnd);// 设置系统公告路径
				JOptionPane.showMessageDialog(EQ.this, "IP设置保存完毕");
			}
		}
	}

	private final class SysUpdateListener implements ActionListener {// 系统更新事件
		public void actionPerformed(final ActionEvent e) {
			String username = preferences.get("username", null);
			String password = preferences.get("password", null);
			if (username == null || password == null) {
				pushMessage("未设置登录升级服务器的用户名或密码");
				return;
			}
			Resource.loginPublic(username, password);
			updateProject();
		}
	}

	private class ChatTreeMouseListener extends MouseAdapter { // 用户列表的监听器
		public void mouseClicked(final MouseEvent e) {
			if (e.getClickCount() == 2) {
				TreePath path = chatTree.getSelectionPath();
				if (path == null)
					return;
				DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
						.getLastPathComponent();
				User user = (User) node.getUserObject();
				try {
					TelFrame.getInstance(ss, new DatagramPacket(new byte[0], 0,
							InetAddress.getByName(user.getIp()), 1111),
							chatTree);
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		}
	}

	private void server() {// 服务器启动方法
		new Thread(new Runnable() {
			public void run() {
				while (true) {
					if (ss != null) {
						byte[] buf = new byte[4096];
						DatagramPacket dp = new DatagramPacket(buf, buf.length);
						try {
							ss.receive(dp);
						} catch (IOException e) {
							e.printStackTrace();
						}
						TelFrame.getInstance(ss, dp, chatTree);
					}
				}
			}
		}).start();
	}

	private void addUserPopup(Component component, final JPopupMenu popup) {// 添加用户弹出菜单
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger())
					showMenu(e);
			}

			public void mouseReleased(MouseEvent e) {

⌨️ 快捷键说明

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