仿QQ聊天软件及源码java版

一直以来,很多java的同志们都没有一个完整资料来参考。把源码贴出来,大家共享!

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Scanner;
import java.util.Stack;
import java.util.prefs.Preferences;import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;public class EQ extends JDialog{private JTextField ipEndTField;private JTextField ipStartTField;private JTextField userNameTField;//用户框private JPasswordField passwordTField;//密码框private JTextField placardPathTField;//placard:公告private JTextField updatePathTField;//更新路径private JTextField pubPathTField;public static EQ frame = null;private ChatTree chatTree;private JPopupMenu popupMenu;//右键菜单private JTabbedPane tabbedPane;//分页面板private JToggleButton searchUserButton;//搜索用户按钮private JProgressBar progressBar;//滚动条private JList faceList;private JButton selectInterfaceOKButton;private DatagramSocket ss;//数据报插座private final JLabel stateLabel;private static String user_dir;private static File localFile;private static File netFile;private String netFilePath;private JButton messageAlertButton;private Stack<String> messageStack;Stack 类表示后进先出(LIFO)的对象堆栈。private ImageIcon messageAlertIcon;private ImageIcon messageAlertNullIcon;private Rectangle location;public static TrayIcon trayicon;private Dao dao;//Preferences.systeRoot:返回系统的根首选项节点   Preferences:参数选择public final static Preferences preferences = Preferences.systemRoot();private JButton userInfoButton;//----------------------------------------------------------------------------------public static void main(String[] args){try{String laf = preferences.get("lookAndFeel", "java默认");if(laf.indexOf("当前系统") > -1){UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}EQ frame = new EQ();frame.setVisible(true);frame.SystemTrayInitial();// 初始化系统栏frame.server();frame.checkPlacard();}catch(Exception e){e.printStackTrace();}}//----------------------------------------------------------------------------------public EQ(){super(new JFrame());frame = this;dao = Dao.getDao();location = dao.getLocation();setTitle("EQ聊天");setBounds(location);progressBar = new JProgressBar();//BevelBorder:该类实现简单的双线斜面边框。Bevel:斜面     lowered:凹入斜面类型。progressBar.setBorder(new BevelBorder(BevelBorder.LOWERED));tabbedPane = new JTabbedPane();popupMenu = new JPopupMenu();chatTree = new ChatTree(this);user_dir = System.getProperty("user.dir");// 程序执行路径用于系统更新localFile = new File(user_dir + File.separator + "EQ.jar");// 本地EQ文件stateLabel = new JLabel();// 状态栏标签this.addWindowListener(new FrameWindowListener());// 添加窗体监视器this.addComponentListener(new ComponentAdapter(){public void componentResized(final ComponentEvent e){saveLocation();}public void componentMoved(final ComponentEvent e){saveLocation();}});try{// 启动通讯服务端口ss = new DatagramSocket(1111);}catch(SocketException e2){if(e2.getMessage().startsWith("Address already in use")){showMessageDialog("服务端口被占用,或者本软件已经运行。");}System.exit(0);}{// 初始化公共信息按钮messageAlertIcon = new ImageIcon(EQ.class.getResource("/image/messageAlert.gif"));messageAlertNullIcon = new ImageIcon(EQ.class.getResource("/image/messageAlertNull20.gif"));messageStack = new Stack<String>();messageAlertButton = new JButton();messageAlertButton.setHorizontalAlignment(SwingConstants.RIGHT);messageAlertButton.setContentAreaFilled(false);//不填充内容区域final JPanel BannerPanel = new JPanel();BannerPanel.setLayout(new BorderLayout());this.add(BannerPanel,BorderLayout.NORTH);userInfoButton = new JButton();BannerPanel.add(userInfoButton,BorderLayout.WEST);userInfoButton.setMargin(new Insets(0,0,0,10));//Margin:边距    insets:插入 initUserInfoButton();// 初始化本地用户头像按钮BannerPanel.add(messageAlertButton,BorderLayout.CENTER);messageAlertButton.addActionListener(new ActionListener(){@Overridepublic void actionPerformed(ActionEvent arg0) {if(!messageStack.empty()){showMessageDialog(messageStack.pop());//堆栈顶部的对象(Vector 对象中的最后一项)。 }}});messageAlertButton.setIcon(messageAlertIcon);showMessageBar();}this.add(tabbedPane,BorderLayout.CENTER);tabbedPane.setTabPlacement(SwingConstants.LEFT);//设置此选项卡窗格的选项卡布局ImageIcon userTicon = new ImageIcon(EQ.class.getResource("/image/tabIcon/tabLeft.PNG"));tabbedPane.addTab(null,userTicon,createUserList(),"用户列表");ImageIcon sysOTicon = new ImageIcon(EQ.class.getResource("/image/tabIcon/tabLeft2.PNG"));tabbedPane.addTab(null, sysOTicon, createSysToolPanel(), "系统操作");ImageIcon sysSTicon = new ImageIcon(EQ.class.getResource("/image/tabIcon/tabLeft3.png"));tabbedPane.addTab(null, sysSTicon, createSysSetPanel(), "系统设置");this.setAlwaysOnTop(true);//总在顶部}//----------------------------------------------------------------------------------private JScrollPane createSysSetPanel(){//系统设置面板final JPanel sysSetPanel = new JPanel();JScrollPane scrollPane = new JScrollPane(sysSetPanel);sysSetPanel.setLayout(new BoxLayout(sysSetPanel,BoxLayout.Y_AXIS));scrollPane.setBorder(new EmptyBorder(0,0,0,0));final JPanel sysPathPanel = new JPanel();sysPathPanel.setMaximumSize(new Dimension(600,200));sysPathPanel.setBorder(new TitledBorder("系统路径"));//title - 边框应显示的标题sysPathPanel.setLayout(new GridLayout(0,1));sysSetPanel.add(sysPathPanel);sysPathPanel.add(new JLabel("程序升级路径"));updatePathTField = new JTextField(preferences.get("updatePath", "请输入路径"));sysPathPanel.add(updatePathTField);sysPathPanel.add(new JLabel("系统公告路径:"));placardPathTField = new JTextField(preferences.get("placardPath","请输入路径"));sysPathPanel.add(placardPathTField);sysPathPanel.add(new JLabel("公共程序路径:"));pubPathTField = new JTextField(preferences.get("pubPath", "请输入路径"));sysPathPanel.add(pubPathTField);final JButton pathOKButton = new JButton("确定");pathOKButton.setActionCommand("sysOK");pathOKButton.addActionListener(new SysSetPanelOKListener());sysSetPanel.add(pathOKButton);final JPanel loginPanel = new JPanel();loginPanel.setMaximumSize(new Dimension(600, 90));loginPanel.setBorder(new TitledBorder("登录升级服务器"));final GridLayout gridLayout_1 = new GridLayout(0, 1);gridLayout_1.setVgap(5);loginPanel.setLayout(gridLayout_1);sysSetPanel.add(loginPanel);final JPanel panel_7 = new JPanel();panel_7.setLayout(new BoxLayout(panel_7, BoxLayout.X_AXIS));loginPanel.add(panel_7);panel_7.add(new JLabel("用户名:"));userNameTField = new JTextField(preferences.get("username", "请输入用户名"));panel_7.add(userNameTField);final JPanel panel_8 = new JPanel();panel_8.setLayout(new BoxLayout(panel_8, BoxLayout.X_AXIS));loginPanel.add(panel_8);panel_8.add(new JLabel("密 码:"));passwordTField = new JPasswordField("*****");panel_8.add(passwordTField);final JButton loginOKButton = new JButton("确定");sysSetPanel.add(loginOKButton);loginOKButton.setActionCommand("loginOK");loginOKButton.addActionListener(new SysSetPanelOKListener());final JPanel ipPanel = new JPanel();final GridLayout gridLayout_2 = new GridLayout(0, 1);gridLayout_2.setVgap(5);ipPanel.setLayout(gridLayout_2);ipPanel.setMaximumSize(new Dimension(600, 90));ipPanel.setBorder(new TitledBorder("IP搜索范围"));sysSetPanel.add(ipPanel);final JPanel panel_5 = new JPanel();panel_5.setLayout(new BoxLayout(panel_5, BoxLayout.X_AXIS));ipPanel.add(panel_5);panel_5.add(new JLabel("起始IP:"));ipStartTField = new JTextField(preferences.get("ipStart", "192.168.0.1"));panel_5.add(ipStartTField);final JPanel panel_6 = new JPanel();panel_6.setLayout(new BoxLayout(panel_6, BoxLayout.X_AXIS));ipPanel.add(panel_6);panel_6.add(new JLabel("终止IP:"));ipEndTField = new JTextField(preferences.get("ipEnd", "192.168.1.255"));panel_6.add(ipEndTField);final JButton ipOKButton = new JButton("确定");ipOKButton.setActionCommand("ipOK");ipOKButton.addActionListener(new SysSetPanelOKListener());sysSetPanel.add(ipOKButton);return scrollPane;}//----------------------------------------------------------------------------------private JScrollPane createUserList(){// 用户列表面板JScrollPane scrollPane = new JScrollPane();scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);addUserPopup(chatTree,getPopupMenu());// 为用户添加弹出菜单scrollPane.setViewportView(chatTree);scrollPane.setBorder(new EmptyBorder(0,0,0,0));chatTree.addMouseListener(new ChatTreeMouseListener());return scrollPane;}//----------------------------------------------------------------------------------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;}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif(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{@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubString 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{// 系统更新事件@Overridepublic void actionPerformed(final ActionEvent e) {// TODO Auto-generated method stubString 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) {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);}}public void pushMessage(String info){// 堆压信息if(!messageStack.contains(info)){messageStack.push(info);}}private void showMessageDialog(String message){JOptionPane.showMessageDialog(this, message);}//----------------------------------------------------------------------------------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 = "TT";String company = "成都市同道科技有限公司";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();} elsetoFront();}});// 系统栏的访问服务器菜单项事件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();}}
}



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/21601.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java 网络编程五 (仿QQ聊天程序)

学完了socket通讯后,在老师的要求下,写了一个仿qq的聊天程序&#xff1a; 最终调试程序结果如下图: 有bug希望提出来,我们一起解决。 设计思路: 在服务器端 用一个HashMap<userName,socket> 维护所有用户相关的信息&#xff0c;从而能够保证和所有的用户进行通讯。 …

Chatgpt论文笔记——GPT1详细解读与可运行的代码

前言 论文&#xff1a;https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf 时间&#xff1a;2018年6月 贡献&#xff1a; 提出了大规模数据上无监督预训练然后在目标任务上有监督finetune的范式。 具体实现 当时由于NLP领域不存…

生成式AI管理规则落地 大模型后时代到来

国家网信办等七部门联合颁布的《生成式人工智能服务管理暂行办法》&#xff0c;给中国生成式AI产业树立了发展规范。 这份监管文件的用意并不止于管控&#xff0c;还用大量的笔墨传递出推动产业发展的原则&#xff0c;尤其强调“鼓励生成式人工智能技术在各行业、各领域的创新…

摄影师没了?!生成式人工智能即将降维打击摄影行业

本文是Mixlab无界社区成员的投稿&#xff1a; 滚石 deepfacelab和deepfacelive项目组成员 摄影师失业了&#xff1f;&#xff1f;怎么说&#xff1f; # # 你还以为AI绘画影响的只是插画师行业吗&#xff1f;错了&#xff0c;摄影行业也即将面临技术洗牌。话不多说&#xff0c;先…

AIGC绘就无限可能的元宇宙

随着科技的飞速发展&#xff0c;我们正逐渐步入一个由虚拟和现实交织构成的全新时代。元宇宙&#xff08;Metaverse&#xff09;作为这个新时代的象征&#xff0c;正在成为一个重要的热点。而人工智能生成内容&#xff08;AIGC&#xff09;技术的结合&#xff0c;将无疑会推动元…

开发者出海合规手册;@levelsio独立开发月入20万解析;MJ+AR设计珠宝;SD算法原理-通俗版 | ShowMeAI日报

&#x1f440;日报&周刊合集 | &#x1f3a1;生产力工具与行业应用大全 | &#x1f9e1; 点赞关注评论拜托啦&#xff01; &#x1f916; 独立开发者必看&#xff0c;出海应用开发者合规手册 这是 JourneymanChina 多年出海经验教训的总结&#xff0c;适用于Google Play 以…

ChatGPT唤醒AI游戏?

配图来自Canva可画 “七天制作新游戏”、“AI全自动完成所有游戏&#xff01;”......继各种AI绘画、AI合成照片、视频之后&#xff0c;AI在游戏领域开启了新一场狂欢。 长久以来&#xff0c;游戏和AI一直有着“相互扶持”的亲密关系——一边是游戏充当AI科研基地&#xff0c…

网易的“草长莺飞二月天”:增长稳健,加码研发,逐浪AI

2月23日&#xff0c;网易发布了2022年第四季度财报。 这是网易与暴雪分道扬镳后的首份财报&#xff0c;加上近期AIGC热度扩散至游戏、教育等各个领域&#xff0c;网易第四季度业绩及其对于GPT等热门技术的探索受到市场关注。 根据财报&#xff0c;第四季度&#xff0c;网易营…

「经济理财」32堂你能听懂的理财课

之前学了一下基金投资课程&#xff0c;作为以后财富管理的积累&#xff0c;可以出门右转看「银行螺丝钉的基金投资课」。但还是觉得应该系统了解一下理财&#xff0c;从小白到理财达人&#xff0c;我需要半年来学习和实践&#xff0c;比较好的是接触到简七理财&#xff0c;结合…

[AI医学] 医学领域几个微调预训练大模型的项目

关键词&#xff1a;AI医学&#xff0c;医学大模型&#xff0c;指令微调&#xff0c;PubMed 文章目录 医学微调大模型1. MedicalGPT-zh2. DoctorGLM3. Huatuo-Llama-Med-Chinese & ChatGLM-Med 医学预训练语言模型1. BioMedLM (2.7B)2. PMC-LLaMA (7B)3. BioMedGPT (1.6B) 总…

程序员专属对联

请欣赏“程序猿春节对联集锦”&#xff1a; 对联一 上联&#xff1a;上拜图灵只佑服务可用 下联&#xff1a; 下跪关公但求永不宕机 横批&#xff1a;风调码顺 风调雨顺 上拜图灵只佑服务可用 下跪关公但求永不宕机 对联二 上联&#xff1a;屏中创造繁华世 下联&#xff1a;指尖…

Node接入ChatGPT 的最强对手Claude

由于个人的chatGPT免费版本即将到期, Claude 很火&#xff0c;在网上被说成是 ChatGPT 的最强对手&#xff0c;是 ChatGPT 的替代品。本文我将介绍下 Claude 是什么&#xff0c;以及如何免费使用 Claude. 什么是Claude 看一下它是如何自我介绍的 Slack Slack 是一款流行的团…

读《EMOQ-TTS: EMOTION INTENSITY QUANTIZATION FOR FINE-GRAINED CONTROLLABLE EMOTIONAL TEXT-TO-SPEECH》

0 Abstract 虽然近年来文本到语音(TTS)的研究取得了显著进展&#xff0c;但仍局限于情感语音合成。为了产生情感话语&#xff0c;大多数作品都利用了从情感标签或参考音频中提取的情感信息。然而&#xff0c;由于话语层面的情绪条件&#xff0c;它们导致了单调的情绪表达。在本…

专家担心 ChatGPT 很快会被用于毁灭性的网络攻击

听到这个新闻&#xff0c;我是挺震惊的&#xff0c;​ChatGPT 近几个月来风靡全球&#xff0c;但就在它以其技术能力让人们惊叹的同时&#xff0c;也有人对其潜在的滥用提出了担忧。 现在&#xff0c;似乎一些 IT 领导者担心它将很快被用于重大网络攻击&#xff0c;并有可能在未…

英文润色网站-英文质量改写改进软件

英文改写软件 英文改写软件是一种全新的工具&#xff0c;它可以方便快捷地对不同语种的图文内容进行批量改写和转换&#xff0c;包括但不限于英语、法语、德语、中文等。无论用户需要将哪种语言的文章进行改写和转换&#xff0c;都可以轻松实现。该软件支持任何文档格式和文本…

OpenAI Translator Bob Plugin Bob上一款翻译、润色、语法修改插件

OpenAI Translator Bob Plugin 一款可以在Bob进行即时翻译的插件。它基于 OpenAI 的 GPT 系列模型&#xff0c;能够提供高质量、准确的翻译服务。该插件支持多种语言的翻译&#xff0c;包括中文、英文、法语、德语、日语等。用户只需在页面中选中需要翻译的文本&#xff0c;然…

pg数据库数据导出

首先得在postgresql的安装包下找到bin目录&#xff0c;找到路径。其次在cmd下面&#xff0c;输入导出路径&#xff1a; 导出数据库的命令&#xff1a; > pg_dump -U postgres -h ip地址 数据库名> f:\data\数据库名.dump >口令&#xff1a;密码

如何进行数据的导出?

如何进行数据的导出&#xff1f; 以前有进行过填写资料并且把资料导出Excel表格&#xff0c;当时就觉得好神奇&#xff0c;又想知道这样的功能是怎么实现的&#xff0c;可是那时的头脑简单&#xff0c;没有知道答案&#xff0c;可是现在我终于知道为什么可以直接导出数据了&am…

图像搜索:以图搜图

以图搜图 随着数字时代的到来&#xff0c;单单的文字搜素已经无法满足人们的搜索了&#xff0c;图像搜索&#xff0c;甚至是视频搜索都已经比较成熟。本文大致讲解下图像搜索&#xff1a; 发展历程 原理 搜索项目&#xff1a;主要分为三个部分——图像特征抽取&#xff0c;构…

图片搜索引擎网站大全,以图搜图网站

当我们需要搜索一些图片的时候使用图片搜索引擎网站可以帮我们更快地找到自己需要的图片&#xff0c;那么有哪些图片搜索引擎网站可以搜索图片呢&#xff1f;下面小编就来和大家分享几个以图搜图的网站。 1.百度图片搜索引擎网站 百度是最大的中文搜索引擎&#xff0c;百度的图…