ServerFrame.java
上传用户:tendy5003
上传日期:2022-07-16
资源大小:210k
文件大小:9k
源码类别:

ICQ/即时通讯

开发平台:

Java

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4. import java.net.*;
  5. import java.util.*;
  6. import javax.swing.*;
  7. //////////*服务器窗口类*///////////////
  8. public class ServerFrame extends JFrame implements ActionListener
  9. {
  10. //服务器信息面板
  11. JPanel pnlServer,pnlServerInfo;
  12. JLabel lblStatus,lblNumber,lblMax,lblServerName,lblProtocol,lblIP,lblPort,lblLog;
  13. JTextField txtStatus,txtNumber,txtMax,txtServerName,txtProtocol,txtIP,txtPort;
  14. JButton btnStop,btnSaveLog;
  15. TextArea taLog;
  16. JTabbedPane tpServer;
  17. TextArea  taMessage;
  18. //用户信息面板
  19. JPanel pnlUser;
  20. JLabel lblMessage,lblUser,lblNotice,lblUserCount;
  21. JList lstUser;
  22. JScrollPane spUser;
  23. JTextField txtNotice;
  24. JButton btnSend,btnKick;
  25. public  ServerFrame()
  26. {
  27.   //服务器窗口
  28.   super("[HappyChat]聊天服务器");
  29.    setSize(550,500);
  30.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.         setResizable(false);    
  32.         Dimension scr=Toolkit.getDefaultToolkit().getScreenSize();//在屏幕居中显示
  33.         Dimension fra=this.getSize();
  34.         if(fra.width>scr.width)
  35.         {
  36.             fra.width=scr.width;
  37.         }
  38.         if(fra.height>scr.height)
  39.         {
  40.             fra.height=scr.height;
  41.         }
  42.         this.setLocation((scr.width-fra.width)/2,(scr.height-fra.height)/2);
  43.                  
  44.     
  45. //==========服务器信息面板=========================
  46.   pnlServer=new JPanel();
  47.   pnlServer.setLayout(null);
  48.   pnlServer.setBackground(new Color(52,130,203));
  49.  
  50.   pnlServerInfo=new JPanel(new GridLayout(14,1));
  51.         pnlServerInfo.setBackground(new Color(52,130,203));
  52.         pnlServerInfo.setFont(new Font("宋体",0,12));
  53.         pnlServerInfo.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(""),BorderFactory.createEmptyBorder(1,1,1,1)));
  54.          
  55.         lblStatus=new JLabel("当前状态:");
  56.         lblStatus.setForeground(Color.YELLOW);
  57.         lblStatus.setFont(new Font("宋体",0,12));
  58.         txtStatus=new JTextField(10);
  59.         txtStatus.setBackground(Color.decode("#d6f4f2"));
  60.         txtStatus.setFont(new Font("宋体",0,12));
  61.         txtStatus.setEditable(false);
  62.          
  63.         lblNumber=new JLabel("当前在线人数:");
  64.         lblNumber.setForeground(Color.YELLOW);
  65.         lblNumber.setFont(new Font("宋体",0,12));
  66.         txtNumber=new JTextField("0 人",10);
  67.         txtNumber.setBackground(Color.decode("#d6f4f2"));
  68.         txtNumber.setFont(new Font("宋体",0,12));
  69.         txtNumber.setEditable(false);
  70.          
  71.         lblMax=new JLabel("最多在线人数:");
  72.         lblMax.setForeground(Color.YELLOW);
  73.         lblMax.setFont(new Font("宋体",0,12));
  74.         txtMax=new JTextField("50 人",10);
  75.         txtMax.setBackground(Color.decode("#d6f4f2"));
  76.         txtMax.setFont(new Font("宋体",0,12));
  77.         txtMax.setEditable(false);
  78.          
  79.         lblServerName=new JLabel("服务器名称:");
  80.         lblServerName.setForeground(Color.YELLOW);
  81.         lblServerName.setFont(new Font("宋体",0,12));
  82.         txtServerName=new JTextField(10);
  83.         txtServerName.setBackground(Color.decode("#d6f4f2"));
  84.         txtServerName.setFont(new Font("宋体",0,12));
  85.         txtServerName.setEditable(false);
  86.          
  87.         lblProtocol=new JLabel("访问协议:");
  88.         lblProtocol.setForeground(Color.YELLOW);
  89.         lblProtocol.setFont(new Font("宋体",0,12));
  90.         txtProtocol=new JTextField("HTTP",10);
  91.         txtProtocol.setBackground(Color.decode("#d6f4f2"));
  92.         txtProtocol.setFont(new Font("宋体",0,12));
  93.         txtProtocol.setEditable(false);
  94.          
  95.         lblIP=new JLabel("服务器IP:");
  96.         lblIP.setForeground(Color.YELLOW);
  97.         lblIP.setFont(new Font("宋体",0,12));
  98.         txtIP=new JTextField(10);
  99.         txtIP.setBackground(Color.decode("#d6f4f2"));
  100.         txtIP.setFont(new Font("宋体",0,12));
  101.         txtIP.setEditable(false);
  102.          
  103.         lblPort=new JLabel("服务器端口:");
  104.         lblPort.setForeground(Color.YELLOW);
  105.         lblPort.setFont(new Font("宋体",0,12));
  106.         txtPort=new JTextField("8000",10);
  107.         txtPort.setBackground(Color.decode("#d6f4f2"));
  108.         txtPort.setFont(new Font("宋体",0,12));
  109.         txtPort.setEditable(false);
  110.          
  111.         btnStop=new JButton("关闭服务器(C)");
  112.         btnStop.setBackground(Color.ORANGE);
  113.         btnStop.setFont(new Font("宋体",0,12));
  114.         
  115.         lblLog=new JLabel("[服务器日志]");
  116.         lblLog.setForeground(Color.YELLOW);
  117.         lblLog.setFont(new Font("宋体",0,12));
  118.          
  119.         taLog=new TextArea(20,50);
  120.         taLog.setFont(new Font("宋体",0,12));
  121.         btnSaveLog=new JButton("保存日志(S)");
  122.         btnSaveLog.setBackground(Color.ORANGE);
  123.         btnSaveLog.setFont(new Font("宋体",0,12));
  124.  
  125.     pnlServerInfo.add(lblStatus);
  126.         pnlServerInfo.add(txtStatus);        
  127.         pnlServerInfo.add(lblNumber);
  128.         pnlServerInfo.add(txtNumber);
  129.         pnlServerInfo.add(lblMax);
  130.         pnlServerInfo.add(txtMax);
  131.         pnlServerInfo.add(lblServerName);
  132.         pnlServerInfo.add(txtServerName);
  133.         pnlServerInfo.add(lblProtocol);
  134.         pnlServerInfo.add(txtProtocol);
  135.         pnlServerInfo.add(lblIP);
  136.         pnlServerInfo.add(txtIP);
  137.         pnlServerInfo.add(lblPort);
  138.         pnlServerInfo.add(txtPort);
  139.          
  140.         pnlServerInfo.setBounds(5,5,100,400);
  141.         lblLog.setBounds(110,5,100,30);
  142.         taLog.setBounds(110,35,400,370);
  143.         btnStop.setBounds(200,410,120,30);
  144.         btnSaveLog.setBounds(320,410,120,30);
  145.         pnlServer.add(pnlServerInfo); 
  146.         pnlServer.add(lblLog);
  147.         pnlServer.add(taLog);
  148.         pnlServer.add(btnStop);
  149.         pnlServer.add(btnSaveLog);
  150.        //===========在线用户面板====================          
  151.         pnlUser=new JPanel();
  152.         pnlUser.setLayout(null);
  153.         pnlUser.setBackground(new Color(52,130,203));
  154.         pnlUser.setFont(new Font("宋体",0,12));
  155.         lblMessage=new JLabel("[用户消息]"); 
  156.         lblMessage.setFont(new Font("宋体",0,12));
  157.         lblMessage.setForeground(Color.YELLOW);
  158.         taMessage=new TextArea(20,20);
  159.         taMessage.setFont(new Font("宋体",0,12));
  160.         lblNotice=new JLabel("通知:");
  161.         lblNotice.setFont(new Font("宋体",0,12));
  162.         txtNotice=new JTextField (20);
  163.         txtNotice.setFont(new Font("宋体",0,12));
  164.         btnSend=new JButton("发送(S)");
  165.         btnSend.setBackground(Color.ORANGE);
  166.         btnSend.setFont(new Font("宋体",0,12));
  167.         btnSend.setEnabled(false);
  168.          
  169.         lblUserCount=new JLabel("在线总人数 0 人");
  170.         lblUserCount.setFont(new Font("宋体",0,12));
  171.  
  172. btnKick=new JButton("踢人(K)");
  173.         btnKick.setBackground(Color.ORANGE);
  174.         btnKick.setFont(new Font("宋体",0,12));
  175.         lblUser=new JLabel("[在线用户列表]"); 
  176.         lblUser.setFont(new Font("宋体",0,12));
  177.         lblUser.setForeground(Color.YELLOW);
  178.         
  179.         lstUser=new JList();
  180.         lstUser.setFont(new Font("宋体",0,12));
  181.         lstUser.setVisibleRowCount(17);
  182.         lstUser.setFixedCellWidth(180);
  183. lstUser.setFixedCellHeight(18);
  184. //        lstUser.setListData(listVector);
  185.          
  186.         spUser=new JScrollPane();
  187.         spUser.setBackground(Color.decode("#d6f4f2"));
  188.         spUser.setFont(new Font("宋体",0,12));
  189.  //spUser.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  190. spUser.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  191. spUser.getViewport().setView(lstUser);
  192. lblMessage.setBounds(5,5,100,25);
  193. taMessage.setBounds(5,35,300,360);
  194. lblUser.setBounds(310,5,100,25);
  195. spUser.setBounds(310,35,220,360);
  196. lblNotice.setBounds(5,410,40,25);
  197. txtNotice.setBounds(50,410,160,25);
  198. btnSend.setBounds(210,410,80,25);
  199. lblUserCount.setBounds(320,410,100,25);
  200. btnKick.setBounds(440,410,80,25);
  201.         pnlUser.add(lblMessage);
  202.         pnlUser.add(taMessage);
  203.         pnlUser.add(lblUser);
  204.         pnlUser.add(spUser);
  205.         pnlUser.add(lblNotice);
  206.         pnlUser.add(txtNotice);
  207.         pnlUser.add(btnSend);
  208.         pnlUser.add(lblUserCount);
  209.         pnlUser.add(btnKick);
  210.         
  211. //============主标签面板========================
  212.         tpServer=new JTabbedPane(JTabbedPane.TOP);
  213.         tpServer.setBackground(Color.decode("#d6f4f2"));
  214.         tpServer.setFont(new Font("宋体",0,12));
  215.         tpServer.add("服务器管理",pnlServer);
  216.         tpServer.add("用户信息管理",pnlUser);
  217.         this.getContentPane().add(tpServer);
  218.         setVisible(true);
  219. }
  220. public void actionPerformed(ActionEvent evt)
  221. {
  222. }
  223. public static void main(String args[])
  224. {
  225. new ServerFrame();
  226. }
  227. }