[Java] fangzhao QQ →→→→→进入此内容的聊天室

来自 , 2019-12-20, 写在 Java, 查看 125 次.
URL http://www.code666.cn/view/fc49306d
  1. package server.serverMain;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Container;
  6. import java.awt.Cursor;
  7. import java.awt.Dialog;
  8. import java.awt.Dimension;
  9. import java.awt.Font;
  10. import java.awt.Toolkit;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.ItemEvent;
  14. import java.awt.event.ItemListener;
  15. import java.awt.event.KeyEvent;
  16. import java.awt.event.KeyListener;
  17. import java.awt.event.MouseEvent;
  18. import java.awt.event.MouseListener;
  19. import java.awt.event.WindowAdapter;
  20. import java.awt.event.WindowEvent;
  21. import java.io.BufferedReader;
  22. import java.io.IOException;
  23. import java.io.InputStreamReader;
  24. import java.sql.Connection;
  25. import java.sql.DriverManager;
  26. import java.sql.ResultSet;
  27. import java.sql.SQLException;
  28. import java.sql.Statement;
  29. import java.util.ArrayList;
  30. import java.util.Date;
  31. import java.util.HashMap;
  32. import java.util.Iterator;
  33. import java.util.Map;
  34.  
  35. import javax.jws.Oneway;
  36. import javax.swing.ImageIcon;
  37. import javax.swing.JButton;
  38. import javax.swing.JComboBox;
  39. import javax.swing.JDialog;
  40. import javax.swing.JFrame;
  41. import javax.swing.JLabel;
  42. import javax.swing.JMenu;
  43. import javax.swing.JMenuBar;
  44. import javax.swing.JMenuItem;
  45. import javax.swing.JOptionPane;
  46. import javax.swing.JPanel;
  47. import javax.swing.JScrollBar;
  48. import javax.swing.JScrollPane;
  49. import javax.swing.JSplitPane;
  50. import javax.swing.JTabbedPane;
  51. import javax.swing.JTable;
  52. import javax.swing.JTextField;
  53. import javax.swing.JTextPane;
  54. import javax.swing.table.AbstractTableModel;
  55. import javax.swing.table.TableColumn;
  56.  
  57. import common.message.node_info;
  58. import common.message.node_public;
  59. import common.message.testMessage;
  60. import server.thread.addFriendsThread.addFriendsThread;
  61. import server.thread.addFriendsThread.authenticationMessageReceiverThread;
  62. import server.thread.addFriendsThread.receiveAgreeRefuseThread;
  63. import server.thread.addqqCanUseThread.addqqCanUseThread;
  64. import server.thread.applicateThread.applicateServerThread;
  65. import server.thread.deleteFridendsThread.deleteFriendsThread;
  66. import server.thread.getAnotherQQIpThread.getAnotherQQIpThread;
  67. import server.thread.getInfoThread.getInfoThread;
  68. import server.thread.groupDealThread.groupDealThread;
  69. import server.thread.heartbeatThread.heartbeatReceiver;
  70. import server.thread.heartbeatThread.judgeAliveThread;
  71. import server.thread.loginThread.loginServerThread;
  72. import server.thread.moveFriendThread.moveFriendThread;
  73. import server.thread.safeThread.judgeWhetherQuestionExistThread;
  74. import server.thread.safeThread.receiveSafeAnswerThread;
  75. import server.thread.safeThread.setSafeQuestionThread;
  76. import server.thread.safeThread.updatePasswordThread;
  77. import server.thread.searchThread.searchThread;
  78. import server.thread.systemMessageThread.sendSystemMessageThread;
  79. import server.thread.systemSettingsThread.systemSettingThread;
  80. import server.thread.updatePersonalInfoThread.updatePersonalInfoThread;
  81. import server.thread.updateRemarkThread.updateRemarkThead;
  82.  
  83. public class serverMain extends JFrame
  84. {
  85.         JPanel j1 = null;
  86.         JPanel j2 = null;
  87.         JPanel j3 = null;
  88.         JPanel j4 = null;
  89.         JScrollPane jsroll0 = null;
  90.         JScrollPane jsroll1 = null;
  91.         JScrollPane jsroll2 = null;
  92.         JScrollPane jsroll3 = null;
  93.         JTextPane textPane0 = null;
  94.         JTextPane textPane1 = null;
  95.         public static JTextPane textPane2 = null;
  96.         JTextField textf_setLimit = null;
  97.         JButton jb_setLimit = null;
  98.         JLabel jlable_setLimit = null;
  99.         JComboBox jcom_setDatabase = null;
  100.         JButton jb_setDatabase = null;
  101.         JLabel jlable_setDatabase = null;
  102.         JTable table = null;
  103.         JLabel jlable1 = null;
  104.         JLabel jlable2 = null;
  105.         JLabel jlable_warning = null;
  106.         JButton jb1 = null;
  107.         JButton jb2 = null;
  108.         JButton jb3 = null;
  109.         JButton jb4 = null;
  110.         MyTableModel myModel = null;
  111.         addqqCanUseThread addCanUse;
  112.         heartbeatReceiver heartbeat;
  113.         judgeAliveThread judgeAlive;
  114.         loginServerThread loginServer;
  115.         applicateServerThread applicateServer;
  116.         searchThread searchServer;
  117.         addFriendsThread addServer;
  118.         authenticationMessageReceiverThread authenticationReceiveServer;
  119.         receiveAgreeRefuseThread agreeRefuseServer;
  120.         deleteFriendsThread deleteServer;
  121.         getAnotherQQIpThread getIpServer;
  122.         getInfoThread getInfoServer;
  123.         judgeWhetherQuestionExistThread getPasswordServer;
  124.         receiveSafeAnswerThread receiverAnswerServer;
  125.         groupDealThread groupDealServer;
  126.         moveFriendThread moveFriendServer;
  127.         setSafeQuestionThread safeQuestionServer;
  128.         systemSettingThread systemSettingServer;
  129.         updatePasswordThread updatePasswordServer;
  130.         updatePersonalInfoThread updatepersonalServer;
  131.         updateRemarkThead updateRemarkServer;
  132.         public static int limit = 100; // 申请次数限制
  133.         public static HashMap<String, node_public> map_onlineInfo = new HashMap<String, node_public>();
  134.         public static HashMap<String, Integer> map_IsSysMessageExist = new HashMap<String, Integer>();
  135.         public static HashMap<String, Date> map_date = new HashMap<String, Date>();
  136.         public static HashMap<String, Integer> map_status = new HashMap<String, Integer>();
  137.         public static HashMap<String, String> map_array_passwordMap = new HashMap<String, String>();
  138.         public static ArrayList<String> array_qqCanUse = new ArrayList<String>();
  139.         public static Connection con1 = null;
  140.         public static Connection con2 = null;
  141.         public static int databaseFlag = 0; // 0是mysql 1是SQLServer 默认mysql
  142.         public static int startFlag = 0;
  143.         private String ip = "localhost";
  144.         private int connectException = 0; // 连接正确与否 1、正确 2、错误
  145.  
  146.         public serverMain()
  147.         {
  148.                 createUserInterface();
  149.                 try
  150.                 {
  151.                         startServer();
  152.                 }
  153.                 catch (Exception e)
  154.                 {
  155.                         JOptionPane.showMessageDialog(null, "服务器启动失败,请查看其是否已经在运行!", "失败",
  156.                                         JOptionPane.ERROR_MESSAGE);
  157.                 }
  158.         }
  159.  
  160.         class refresh extends Thread
  161.         {}
  162.  
  163.         private void createUserInterface()
  164.         {
  165.                 Container contentPane = getContentPane();
  166.                 contentPane.setBackground(Color.WHITE);
  167.                 contentPane.setLayout(null);
  168.                 //
  169.                 //
  170.                 // 系统消息
  171.                 j1 = new JPanel();
  172.                 j1.setLayout(null);
  173.                 //
  174.                 jlable1 = new JLabel("已发送的系统消息:");
  175.                 jlable1.setFont(new Font("宋体", Font.PLAIN, 12));
  176.                 jlable1.setBounds(0, 0, 120, 15);
  177.                 j1.add(jlable1);
  178.                 //
  179.                 //
  180.                 textPane0 = new JTextPane();
  181.                 textPane0.setEditable(false);
  182.                 textPane0.setFont(new Font("宋体", Font.PLAIN, 12));
  183.                 textPane0.setDisabledTextColor(Color.red);
  184.                 textPane0.setBounds(0, 20, 600, 180);
  185.                 j1.add(textPane0);
  186.                 jsroll0 = new JScrollPane(textPane0);
  187.                 jsroll0.setBounds(0, 20, 590, 180);
  188.                 jsroll0.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  189.                 j1.add(jsroll0);
  190.                 //
  191.                 //
  192.                 jlable2 = new JLabel("请在下面输入系统消息,按ctrl+enter发送:");
  193.                 jlable2.setBounds(0, 200, 250, 15);
  194.                 jlable2.setFont(new Font("宋体", Font.PLAIN, 12));
  195.                 j1.add(jlable2);
  196.                 //
  197.                 jb1 = new JButton("清空已发送");
  198.                 jb1.setBounds(470, 202, 100, 15);
  199.                 jb1.setFont(new Font("宋体", Font.PLAIN, 12));
  200.                 j1.add(jb1);
  201.                 jb1.addActionListener(new ActionListener() {
  202.                         @Override
  203.                         public void actionPerformed(ActionEvent e)
  204.                         {
  205.                                 jb1ActionPerfromed(e);
  206.                         }
  207.                 });
  208.                 //
  209.                 textPane1 = new JTextPane();
  210.                 textPane1.setBounds(0, 220, 600, 80);
  211.                 textPane1.setFont(new Font("宋体", Font.PLAIN, 12));
  212.                 j1.add(textPane1);
  213.                 jsroll3 = new JScrollPane(textPane1);
  214.                 jsroll3.setBounds(0, 220, 590, 80);
  215.                 jsroll3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  216.                 j1.add(jsroll3);
  217.                 //
  218.                 jb2 = new JButton("发送");
  219.                 jb2.setBounds(470, 302, 100, 15);
  220.                 jb2.setFont(new Font("宋体", Font.PLAIN, 12));
  221.                 j1.add(jb2);
  222.                 jb2.addActionListener(new ActionListener() {
  223.                         @Override
  224.                         public void actionPerformed(ActionEvent e)
  225.                         {
  226.                                 try
  227.                                 {
  228.                                         jb2ActionPerfromed(e);
  229.                                 }
  230.                                 catch (SQLException e1)
  231.                                 {
  232.                                         // TODO Auto-generated catch block
  233.                                         e1.printStackTrace();
  234.                                 }
  235.                         }
  236.                 });
  237.                 //
  238.                 // 系统日志
  239.                 j2 = new JPanel();
  240.                 j2.setLayout(null);
  241.                 textPane2 = new JTextPane();
  242.                 textPane2.setBounds(0, 0, 600, 300);
  243.                 textPane2.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
  244.                 textPane2.setText("系统日志:\n");
  245.                 textPane2.setFont(new Font("宋体", Font.PLAIN, 12));
  246.                 textPane2.setEditable(false);
  247.                 j2.add(textPane2);
  248.                 jsroll1 = new JScrollPane(textPane2);
  249.                 jsroll1.setBounds(0, 0, 590, 300);
  250.                 jsroll1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  251.                 j2.add(jsroll1);
  252.                 jb3 = new JButton("清空");
  253.                 jb3.setBounds(470, 302, 100, 15);
  254.                 jb3.setFont(new Font("宋体", Font.PLAIN, 12));
  255.                 j2.add(jb3);
  256.                 jb3.addActionListener(new ActionListener() {
  257.                         public void actionPerformed(ActionEvent e)
  258.                         {
  259.                                 jb3ActionPerfromed(e);
  260.                         }
  261.                 });
  262.                 //
  263.                 j3 = new JPanel();
  264.                 j3.setLayout(null);
  265.                 // 表格
  266.                 myModel = new MyTableModel();
  267.                 table = new JTable(myModel);
  268.                 table.setEnabled(true);
  269.                 table.setRowSelectionAllowed(true);// 设置可否被选择.默认为false
  270.                 table.setShowHorizontalLines(true);
  271.                 table.setShowVerticalLines(true);
  272.                 table.setGridColor(Color.blue);
  273.                 table.setBounds(0, 0, 600, 200);
  274.                 jsroll2 = new JScrollPane(table);
  275.                 jsroll2.setBounds(0, 0, 590, 300);
  276.                 jsroll2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  277.                 j3.add(jsroll2);
  278.                 //
  279.                 jb4 = new JButton("刷新");
  280.                 jb4.setBounds(470, 302, 100, 15);
  281.                 jb4.setFont(new Font("宋体", Font.PLAIN, 12));
  282.                 j3.add(jb4);
  283.                 jb4.addActionListener(new ActionListener() {
  284.                         @Override
  285.                         public void actionPerformed(ActionEvent e)
  286.                         {
  287.                                 jb4ActionPerfromed(e);
  288.                         }
  289.                 });
  290.                
  291.                 j4 = new JPanel();
  292.                 j4.setLayout(null);
  293.                 jlable_setLimit = new JLabel("同一个IP一天可申请的次数:");
  294.                 jlable_setLimit.setBounds(10, 10, 200, 20);
  295.                 textf_setLimit = new JTextField();
  296.                 textf_setLimit.setBounds(200, 10, 90, 20);
  297.                 jb_setLimit = new JButton("确定");
  298.                 jb_setLimit.setBounds(300, 10, 60, 20);
  299.                 jb_setLimit.setFont(new Font("宋体", Font.PLAIN, 12));
  300.                 j4.add(jlable_setLimit);
  301.                 j4.add(jb_setLimit);
  302.                 j4.add(textf_setLimit);
  303.                 jb_setLimit.addActionListener(new ActionListener() {
  304.                         @Override
  305.                         public void actionPerformed(ActionEvent e)
  306.                         {
  307.                                 jb_setActionPerfromed(e);
  308.                         }
  309.                 });
  310.                 jlable_setDatabase = new JLabel("请选择连接数据库:");
  311.                 jlable_setDatabase.setBounds(10, 40, 200, 20);
  312.                 String item[] = { "MySql", "SQLServer" };
  313.                 jcom_setDatabase = new JComboBox(item);
  314.                 jcom_setDatabase.setBounds(200, 40, 90, 20);
  315.                 jlable_warning = new JLabel("(提示:请先停止服务器再更改此选项!)");
  316.                 jlable_warning.setBounds(300, 40, 300, 20);
  317.                 jlable_warning.setFont(new Font("宋体", Font.PLAIN, 12));
  318.                 j4.add(jlable_setDatabase);
  319.                 j4.add(jcom_setDatabase);
  320.                 j4.add(jlable_warning);
  321.                 jcom_setDatabase.addItemListener(new ItemListener() {
  322.                         @Override
  323.                         public void itemStateChanged(ItemEvent e)
  324.                         {
  325.                                 jcom_setDatabaseStateChanged(e);
  326.                         }
  327.                 });
  328.                 //
  329.                 JTabbedPane tab = new JTabbedPane();
  330.                 tab.setBounds(0, 0, 600, 400);
  331.                 tab.addTab("系统日志", j2);
  332.                 tab.addTab("发送系统消息", j1);
  333.                 tab.addTab("在线情况", j3);
  334.                 tab.addTab("系统设置", j4);
  335.                 tab.setFont(new Font("宋体", Font.PLAIN, 12));
  336.                 contentPane.add(tab);
  337.                 Menu m = new Menu();
  338.                 m.setFont(new Font("宋体", Font.PLAIN, 12));
  339.                 this.setJMenuBar(m);
  340.                 Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
  341.                 Dimension framesize = this.getSize();
  342.                 int x = (screensize.width - framesize.width) / 5;
  343.                 int y = (screensize.height - framesize.height) / 5;
  344.                 this.setLocation(x, y);
  345.                 this.show();
  346.                 setTitle("飞Q2012服务器");
  347.                 // this.setIconImage(new ImageIcon("\\icon.jpg").getImage());
  348.                 setResizable(false);
  349.                 setSize(600, 400);
  350.                 setVisible(true);
  351.                 // ------------------------给textPane1添加键盘事件--------------------------------//
  352.                 textPane1.addKeyListener(new KeyListener() {
  353.                         public void keyPressed(KeyEvent e)
  354.                         {
  355.                                 if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_ENTER)
  356.                                 {
  357.                                         try
  358.                                         {
  359.                                                 if (startFlag == 1)
  360.                                                 {
  361.                                                         sendSystemMessageThread sendSys = new sendSystemMessageThread(
  362.                                                                         textPane1.getText());
  363.                                                         textPane0.setText(textPane0.getText()
  364.                                                                         + (new Date()) + ":" + textPane1.getText()
  365.                                                                         + "\n");
  366.                                                         textPane1.setText("");
  367.                                                 }
  368.                                                 else
  369.                                                 {
  370.                                                         JOptionPane.showMessageDialog(null,
  371.                                                                         "服务器已停止运行,请启动后再发系统消息!", "系统信息",
  372.                                                                         JOptionPane.INFORMATION_MESSAGE);
  373.                                                         textPane1.setText("");
  374.                                                 }
  375.                                         }
  376.                                         catch (SQLException e1)
  377.                                         {
  378.                                                 // TODO Auto-generated catch block
  379.                                                 e1.printStackTrace();
  380.                                         }
  381.                                 }
  382.                         }
  383.  
  384.                         public void keyTyped(KeyEvent e)
  385.                         {
  386.                                 if (e.getKeyChar() >= '0' && e.getKeyChar() <= '9')
  387.                                 {}
  388.                         }
  389.  
  390.                         public void keyReleased(KeyEvent e)
  391.                         {}
  392.                 });
  393.                 // ---------------------------------------------------------------------//
  394.         }
  395.  
  396.         protected void jcom_setDatabaseStateChanged(ItemEvent e)
  397.         {
  398.                 databaseFlag = jcom_setDatabase.getSelectedIndex();
  399.         }
  400.  
  401.         protected void jb_setActionPerfromed(ActionEvent e)
  402.         {
  403.                 String str1 = textf_setLimit.getText();
  404.                 if (str1.equals(""))
  405.                 {
  406.                         JOptionPane.showMessageDialog(null, "输入 不能为空!", "输入错误",
  407.                                         JOptionPane.ERROR_MESSAGE);
  408.                         return;
  409.                 }
  410.                 for (int i = 0; i < str1.length(); i++)
  411.                 {
  412.                         if (str1.charAt(i) < '0' || str1.charAt(i) > '9')
  413.                         {
  414.                                 textf_setLimit.setText("");
  415.                                 JOptionPane.showMessageDialog(null, "输入的只能是数字!", "输入错误",
  416.                                                 JOptionPane.ERROR_MESSAGE);
  417.                                 return;
  418.                         }
  419.                 }
  420.                 limit = Integer.parseInt(str1);
  421.                 textf_setLimit.setText("");
  422.                 JOptionPane.showMessageDialog(null, "设置成功!", "设置成功",
  423.                                 JOptionPane.INFORMATION_MESSAGE);
  424.         }
  425.  
  426.         protected void jb4ActionPerfromed(ActionEvent e)
  427.         {
  428.                 myModel = new MyTableModel();
  429.                 table.setModel(myModel);
  430.                 table.repaint();
  431.         }
  432.  
  433.         protected void jb3ActionPerfromed(ActionEvent e)
  434.         {
  435.                 textPane2.setText("");
  436.                 textPane2.setText("系统日志:\n");
  437.         }
  438.  
  439.         protected void jb2ActionPerfromed(ActionEvent e) throws SQLException
  440.         {
  441.                 if (startFlag == 1)
  442.                 {
  443.                         sendSystemMessageThread sendSys = new sendSystemMessageThread(
  444.                                         textPane1.getText());
  445.                         textPane0.setText(textPane0.getText() + (new Date()) + ":"
  446.                                         + textPane1.getText() + "\n");
  447.                         textPane1.setText("");
  448.                 }
  449.                 else
  450.                 {
  451.                         JOptionPane.showMessageDialog(null, "服务器已停止运行,请启动后再发系统消息!", "系统信息",
  452.                                         JOptionPane.INFORMATION_MESSAGE);
  453.                         textPane1.setText("");
  454.                 }
  455.         }
  456.  
  457.         protected void jb1ActionPerfromed(ActionEvent e)
  458.         {
  459.                 textPane0.setText("");
  460.         }
  461.  
  462.         // 菜单
  463.         class Menu extends JMenuBar
  464.         {
  465.                 private JDialog aboutDialog;
  466.  
  467.                 /**
  468.                  * 菜单初始化操作
  469.                  */
  470.                 public Menu()
  471.                 {
  472.                         JMenu fileMenu1 = new JMenu("文件");
  473.                         JMenu fileMenu2 = new JMenu("操作");
  474.                         JMenu fileMenu3 = new JMenu("帮助");
  475.                         JMenuItem aboutMenuItem = new JMenuItem("关于...");
  476.                         JMenuItem exitMenuItem = new JMenuItem("退出");
  477.                         JMenuItem startMenuItem = new JMenuItem("重启服务器");
  478.                         JMenuItem stopMenuItem = new JMenuItem("停止服务器");
  479.                         fileMenu1.setFont(new Font("宋体", Font.PLAIN, 12));
  480.                         fileMenu2.setFont(new Font("宋体", Font.PLAIN, 12));
  481.                         fileMenu3.setFont(new Font("宋体", Font.PLAIN, 12));
  482.                         aboutMenuItem.setFont(new Font("宋体", Font.PLAIN, 12));
  483.                         exitMenuItem.setFont(new Font("宋体", Font.PLAIN, 12));
  484.                         startMenuItem.setFont(new Font("宋体", Font.PLAIN, 12));
  485.                         stopMenuItem.setFont(new Font("宋体", Font.PLAIN, 12));
  486.                         fileMenu1.add(exitMenuItem);
  487.                         fileMenu2.add(startMenuItem);
  488.                         fileMenu2.add(stopMenuItem);
  489.                         fileMenu3.add(aboutMenuItem);
  490.                         this.add(fileMenu1);
  491.                         this.add(fileMenu2);
  492.                         this.add(fileMenu3);
  493.                         aboutDialog = new JDialog();
  494.                         initAboutDialog();
  495.                         // 菜单事件
  496.                         exitMenuItem.addActionListener(new ActionListener() {
  497.                                 public void actionPerformed(ActionEvent e)
  498.                                 {
  499.                                         String sql_update = "update mainInfo set status = 0;";
  500.                                         dispose();
  501.                                         try
  502.                                         {
  503.                                                 con1.createStatement().execute(sql_update);
  504.                                         }
  505.                                         catch (SQLException e1)
  506.                                         {
  507.                                                 // TODO Auto-generated catch block
  508.                                                 e1.printStackTrace();
  509.                                         }
  510.                                         System.exit(0);
  511.                                 }
  512.                         });
  513.                         aboutMenuItem.addActionListener(new ActionListener() {
  514.                                 public void actionPerformed(ActionEvent e)
  515.                                 {
  516.                                         aboutDialog.show();
  517.                                 }
  518.                         });
  519.                         startMenuItem.addActionListener(new ActionListener() {
  520.                                 @Override
  521.                                 public void actionPerformed(ActionEvent e)
  522.                                 {
  523.                                         try
  524.                                         {
  525.                                                 stopServer();
  526.                                                 Thread.sleep(2000);
  527.                                                 startServer();
  528.                                                 textPane2.setText(textPane2.getText() + (new Date())
  529.                                                                 + ":" + "服务器重新启动成功!\n");
  530.                                                 JOptionPane.showMessageDialog(null, "服务器重启成功!", "系统信息",
  531.                                                                 JOptionPane.INFORMATION_MESSAGE);
  532.                                         }
  533.                                         catch (Exception e1)
  534.                                         {
  535.                                                 // TODO Auto-generated catch block
  536.                                                 e1.printStackTrace();
  537.                                         }
  538.                                 }
  539.                         });
  540.                         stopMenuItem.addActionListener(new ActionListener() {
  541.                                 @Override
  542.                                 public void actionPerformed(ActionEvent e)
  543.                                 {
  544.                                         try
  545.                                         {
  546.                                                 stopServer();
  547.                                                 JOptionPane.showMessageDialog(null, "服务器已停止运行!",
  548.                                                                 "系统信息", JOptionPane.INFORMATION_MESSAGE);
  549.                                         }
  550.                                         catch (Exception e1)
  551.                                         {
  552.                                                 // TODO Auto-generated catch block
  553.                                                 e1.printStackTrace();
  554.                                         }
  555.                                 }
  556.                         });
  557.                         setFont(new Font("宋体", Font.PLAIN, 12));
  558.                 }
  559.  
  560.                 /**
  561.                  * 返回关于对话框
  562.                  */
  563.                 public JDialog getAboutDialog()
  564.                 {
  565.                         return aboutDialog;
  566.                 }
  567.  
  568.                 /**
  569.                  * 设置"关于"对话框的外观及响应事件,操作和JFrame一样都是在内容 框架上进行的
  570.                  */
  571.                 public void initAboutDialog()
  572.                 {
  573.                         aboutDialog.setTitle("关于QQserver");
  574.                         Container con = aboutDialog.getContentPane();
  575.                         // Swing 中使用html语句
  576.                         JLabel aboutLabel = new JLabel(
  577.                                         "<html><b>"
  578.                                                         + "<center><br>QQserver</br><br>verson:1.0</br><br>Copyright © 2011 sdust,All rights reserved 版权所有 山东科技大学 王昌帅 司吉峰 王松松</br></html></b>",
  579.                                         JLabel.CENTER);
  580.                         aboutLabel.setFont(new Font("宋体", Font.PLAIN, 15));
  581.                         con.add(aboutLabel, BorderLayout.CENTER);
  582.                         aboutDialog.setResizable(false);
  583.                         aboutDialog.setSize(600, 200);
  584.                         aboutDialog.setLocation(205, 300);
  585.                 }
  586.         }
  587.  
  588.         protected void processWindowEvent(WindowEvent e)
  589.         {
  590.                 if (e.getID() == WindowEvent.WINDOW_CLOSING)
  591.                 {
  592.                         String sql_update = "update mainInfo set status = 0;";
  593.                         dispose();
  594.                         try
  595.                         {
  596.                                 con1.createStatement().execute(sql_update);
  597.                         }
  598.                         catch (SQLException e1)
  599.                         {
  600.                                 // TODO Auto-generated catch block
  601.                                 e1.printStackTrace();
  602.                         }
  603.                         System.exit(0);
  604.                 }
  605.                 else
  606.                 {
  607.                         super.processWindowEvent(e);
  608.                 }
  609.         }
  610.  
  611.         // 启动服务器
  612.         public void startServer()
  613.         {
  614.                 try
  615.                 {
  616.                         if (databaseFlag == 0)
  617.                         {
  618.                                 System.out.println("链接mysql");
  619.                                 // 定义MySQL的数据库驱动程序
  620.                                 String DBDRIVER = "com.mysql.jdbc.Driver";
  621.                                 // 定义MySQL数据库的连接地址
  622.                                 /*String DBURL1 = "jdbc:mysql://" + ip
  623.                                                 + ":3306/main?useUnicode=true&characterEncoding=utf8";
  624.                                 String DBURL2 = "jdbc:mysql://" + ip
  625.                                                 + ":3306/users?useUnicode=true&characterEncoding=utf8";*/
  626.                                 //jdbc\:mysql\://localhost\:3306/manchar2
  627.                                 String DBURL1 = "jdbc:mysql://localhost:3306/main?useUnicode=true&characterEncoding=utf8";
  628.                                 String DBURL2 = "jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=utf8";
  629.                                 // MySQL数据库的连接用户名
  630.                                 String DBUSER = "root";
  631.                                 // MySQL数据库的连接密码
  632.                                 String DBPASS = "root";
  633.                                 Class.forName(DBDRIVER); // 加载驱动程序
  634.                                 con1 = DriverManager.getConnection(DBURL1, DBUSER, DBPASS);
  635.                                 con2 = DriverManager.getConnection(DBURL2, DBUSER, DBPASS);
  636.                                 textPane2.setText(textPane2.getText() + (new Date()) + ":"
  637.                                                 + "已连接MySQL数据库\n");
  638.                         }
  639.                         else
  640.                         {
  641.                                 // /////////////////////////////////////////////////////
  642.                                 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  643.                                 String url1 = "jdbc:sqlserver://" + ip
  644.                                                 + ":1433;DatabaseName=main;";
  645.                                 String url2 = "jdbc:sqlserver://" + ip
  646.                                                 + ":1433;DatabaseName=users;";
  647.                                 String user = "sa";
  648.                                 String password = "yizhan";
  649.                                 con1 = DriverManager.getConnection(url1, user, password);
  650.                                 con2 = DriverManager.getConnection(url2, user, password);
  651.                                 // ////////////////////////////////////////////////////////
  652.                                 textPane2.setText(textPane2.getText() + (new Date()) + ":"
  653.                                                 + "已连接SQLServer数据库\n");
  654.                         }
  655.                 }
  656.                 catch (Exception ex)
  657.                 {
  658.                         JOptionPane.showMessageDialog(null, "连接数据库失败!", "系统信息",
  659.                                         JOptionPane.ERROR_MESSAGE);
  660.                         connectException = 1;
  661.                         return;
  662.                 }
  663.                 try
  664.                 //
  665.                 {
  666.                         String sql = "select * from Password;";// 预读密码
  667.                         Statement state = con1.createStatement();
  668.                         ResultSet res = state.executeQuery(sql);
  669.                         while (res.next())
  670.                         {
  671.                                 map_array_passwordMap.put(res.getString("qq"),
  672.                                                 res.getString("password"));
  673.                         }
  674.                         String sql_sys = "select * from systemMessage;";// 预读系统消息
  675.                         ResultSet res_sys = state.executeQuery(sql_sys);
  676.                         while (res_sys.next())
  677.                         {
  678.                                 if (res_sys.getString("warning") != null)
  679.                                         map_IsSysMessageExist.put(res_sys.getString("qq"), 1);
  680.                                 else
  681.                                         map_IsSysMessageExist.put(res_sys.getString("qq"), 0);
  682.                         }
  683.                 }
  684.                 catch (SQLException e)
  685.                 {
  686.                         JOptionPane.showMessageDialog(null, "预读数据库信息失败!", "系统信息",
  687.                                         JOptionPane.ERROR_MESSAGE);
  688.                         connectException = 1;
  689.                         return;
  690.                 }
  691.                 try
  692.                 {
  693.                         addCanUse = new addqqCanUseThread();
  694.                         heartbeat = new heartbeatReceiver();
  695.                         judgeAlive = new judgeAliveThread();
  696.                         loginServer = new loginServerThread();
  697.                         applicateServer = new applicateServerThread();
  698.                         searchServer = new searchThread();
  699.                         addServer = new addFriendsThread();
  700.                         authenticationReceiveServer = new authenticationMessageReceiverThread();
  701.                         agreeRefuseServer = new receiveAgreeRefuseThread();
  702.                         deleteServer = new deleteFriendsThread();
  703.                         getIpServer = new getAnotherQQIpThread();
  704.                         getInfoServer = new getInfoThread();
  705.                         getPasswordServer = new judgeWhetherQuestionExistThread();
  706.                         receiverAnswerServer = new receiveSafeAnswerThread();
  707.                         groupDealServer = new groupDealThread();
  708.                         moveFriendServer = new moveFriendThread();
  709.                         safeQuestionServer = new setSafeQuestionThread();
  710.                         systemSettingServer = new systemSettingThread();
  711.                         updatePasswordServer = new updatePasswordThread();
  712.                         updatepersonalServer = new updatePersonalInfoThread();
  713.                         updateRemarkServer = new updateRemarkThead();
  714.                 }
  715.                 catch (Exception e)
  716.                 {
  717.                         JOptionPane.showMessageDialog(null, "启动服务器子程序异常,请重启!", "系统信息",
  718.                                         JOptionPane.ERROR_MESSAGE);
  719.                         connectException = 1;
  720.                         return;
  721.                 }
  722.                 startFlag = 1;
  723.                 jcom_setDatabase.setEnabled(false);
  724.                 textPane2.setText(textPane2.getText() + (new Date()) + ":"
  725.                                 + "服务器启动成功!\n");
  726.         }
  727.  
  728.         @SuppressWarnings("deprecation")
  729.         public void stopServer() throws ClassNotFoundException, SQLException,
  730.                         IOException, InterruptedException
  731.         {
  732.                 if (connectException != 1)
  733.                 {
  734.                         addCanUse.stop();
  735.                         heartbeat.stop();
  736.                         judgeAlive.stop();
  737.                         loginServer.stop();
  738.                         applicateServer.stop();
  739.                         searchServer.stop();
  740.                         addServer.stop();
  741.                         authenticationReceiveServer.stop();
  742.                         agreeRefuseServer.stop();
  743.                         deleteServer.stop();
  744.                         getIpServer.stop();
  745.                         getInfoServer.stop();
  746.                         getPasswordServer.stop();
  747.                         receiverAnswerServer.stop();
  748.                         groupDealServer.stop();
  749.                         moveFriendServer.stop();
  750.                         safeQuestionServer.stop();
  751.                         systemSettingServer.stop();
  752.                         updatePasswordServer.stop();
  753.                         updatepersonalServer.stop();
  754.                         updateRemarkServer.stop();
  755.                         heartbeat.server.close();
  756.                         loginServer.server.close();
  757.                         applicateServer.server.close();
  758.                         searchServer.server.close();
  759.                         addServer.server.close();
  760.                         authenticationReceiveServer.server.close();
  761.                         agreeRefuseServer.server.close();
  762.                         deleteServer.server.close();
  763.                         getIpServer.server.close();
  764.                         getInfoServer.server.close();
  765.                         getPasswordServer.server.close();
  766.                         receiverAnswerServer.server.close();
  767.                         groupDealServer.server.close();
  768.                         moveFriendServer.server.close();
  769.                         safeQuestionServer.server.close();
  770.                         systemSettingServer.server.close();
  771.                         updatePasswordServer.server.close();
  772.                         updatepersonalServer.server.close();
  773.                         updateRemarkServer.server.close();
  774.                         map_date.clear();
  775.                         map_IsSysMessageExist.clear();
  776.                         map_onlineInfo.clear();
  777.                         map_status.clear();
  778.                         map_array_passwordMap.clear();
  779.                         array_qqCanUse.clear();
  780.                         String sql_update = "update mainInfo set status = 0;";
  781.                         con1.createStatement().execute(sql_update);
  782.                         startFlag = 0;
  783.                         jcom_setDatabase.setEnabled(true);
  784.                         textPane2.setText(textPane2.getText() + (new Date()) + ":"
  785.                                         + "服务器已停止!\n");
  786.                 }
  787.         }
  788.  
  789.         class MyTableModel extends AbstractTableModel
  790.         {
  791.                 int count = map_onlineInfo.size();
  792.                 private String[] columnNames = { "QQ", "ip", "main_port", "sys_port",
  793.                                 "heartbeat_port", "chat_port" };
  794.                 private String[][] data = new String[count][];
  795.  
  796.                 public MyTableModel()
  797.                 {
  798.                         Map m = serverMain.map_onlineInfo;
  799.                         Iterator ite = m.keySet().iterator();
  800.                         for (int i = 0; ite.hasNext(); i++)
  801.                         {
  802.                                 Object key = ite.next();
  803.                                 data[i] = new String[6];
  804.                                 data[i][0] = key.toString();
  805.                                 data[i][1] = map_onlineInfo.get(key).ip;
  806.                                 data[i][2] = "" + map_onlineInfo.get(key).port_main;
  807.                                 data[i][3] = "" + map_onlineInfo.get(key).port_sys;
  808.                                 data[i][4] = "" + map_onlineInfo.get(key).port_alive;
  809.                                 data[i][5] = "" + map_onlineInfo.get(key).port_chat;
  810.                         }
  811.                 }
  812.  
  813.                 public int getColumnCount()
  814.                 {
  815.                         return columnNames.length;
  816.                 }
  817.  
  818.                 public int getRowCount()
  819.                 {
  820.                         return data.length;
  821.                 }
  822.  
  823.                 public String getColumnName(int col)
  824.                 {
  825.                         return columnNames[col];
  826.                 }
  827.  
  828.                 public String getValueAt(int row, int col)
  829.                 {
  830.                         return data[row][col];
  831.                 }
  832.  
  833.                 public Class getColumnClass(int c)
  834.                 {
  835.                         return getValueAt(0, c).getClass();
  836.                 }
  837.  
  838.                 public boolean isCellEditable(int row, int col)
  839.                 {
  840.                         return false;
  841.                 }
  842.         }
  843.  
  844.         public static void main(String args[]) throws ClassNotFoundException,
  845.                         SQLException, IOException, InterruptedException
  846.         {
  847.                 serverMain server = new serverMain();
  848.         }
  849. }
  850.  

回复 "fangzhao QQ"

这儿你可以回复上面这条便签

captcha