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

📄 maingui.java

📁 企业级的即时通软件。。java语言写的 这是服务端部份。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			}
		});
		menuItem_3.setText("启动服务");
		menu_5.add(menuItem_3);

		final JMenuItem menuItem_4 = new JMenuItem();
		menuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				int i=JOptionPane.showConfirmDialog(frame,"停止服务后再启动服务需重新登录,确定要停止服务?","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
		 		if(i==0)
		 		{
		 			try {
		 				if(serverSocket!=null)serverSocket.close();
		 				t.interrupt();//中断服务线程
						MainGUI.label.setText("处于停止服务中..");
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					textArea.append("系统提示:"+"   聊天服务器"+"   已经停止\n");
		 		}
			}
		});
		menuItem_4.setText("停止服务");
		menu_5.add(menuItem_4);

		final JMenu menu_8 = new JMenu();
		menu_8.setText("查看");
		menuBar.add(menu_8);

		final JMenuItem menuItem_18 = new JMenuItem();
		menuItem_18.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				new ShowAllUserInfoGUI().showGUI();
			}
		});
		menuItem_18.setText("所有用户信息");
		menu_8.add(menuItem_18);

		final JMenuItem menuItem_19 = new JMenuItem();
		menuItem_19.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				new ShowMasterAllInfo().showGUI();
			}
		});
		menuItem_19.setText("所有普通管理员");
		menu_8.add(menuItem_19);

		final JMenu menu_9 = new JMenu();
		menu_9.setText("关于");
		menuBar.add(menu_9);

		final JMenuItem menuItem_1 = new JMenuItem();
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				new ShowAnent().showGUI();
			}
		});
		menuItem_1.setText("程序");
		menu_9.add(menuItem_1);

		time = new JLabel();
		time.setText("当前日期为:");
		time.setBounds(331, 405, 128, 26);
		frame.getContentPane().add(time);

		happylabel = new JLabel();
		happylabel.setBounds(10, 411, 277, 15);
		happylabel.setText("    "+name+" 欢迎使用企业即时通 ...");
		frame.getContentPane().add(happylabel);

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(0, -2, 461, 37);
		frame.getContentPane().add(panel);

		final JToolBar toolBar_1 = new JToolBar();
		toolBar_1.setBounds(0, 5, 535, 33);
		panel.add(toolBar_1);

		final JButton button = new JButton();
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				if(serverSocket   ==   null)   
                {   
                        try   
                        {   
                        	    serverSocket   =   new   ServerSocket(MainGUI.SOCKET);
                        	    MainGUI.label.setText("当前在线人数为: 0");
                                textArea.append("系统提示:"+"   聊天服务器"+"   正在启动......\n");   
                                textArea.append("系统提示:"+"   聊天服务器"+"   启动完成......\n");   
                        }   
                        catch(IOException   ex)   
                        {   
                        	textArea.append("系统提示:"+"   聊天服务器"+"   启动失败!\n");   
                        }   
                }   
                else   
                {   
                	textArea.append("系统提示:"+"   聊天服务器"+"   已经启动\n");   
                }   
                //启动监听客户端连接线程   
                t.start();
        }   
		});
		button.addMouseListener(new MouseAdapter() {
			public void mouseEntered(final MouseEvent e) {
				button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F1.png"));
			}
			public void mouseExited(final MouseEvent e) {
				button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F2.png"));
			}
		});
		button.setToolTipText("启动服务"); 
		button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F2.png"));
		toolBar_1.add(button);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				int i=JOptionPane.showConfirmDialog(frame,"停止服务后再启动服务需重新登录,确定要停止服务?","注意",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
		 		if(i==0)
		 		{
		 			try{
		 				if(serverSocket!=null)serverSocket.close();
		 				t.interrupt();//中断服务线程
						MainGUI.label.setText("处于停止服务中..");
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					textArea.append("系统提示:"+"   聊天服务器"+"   已经停止\n");
		 		}
			}
		});
		button_1.addMouseListener(new MouseAdapter() {
			public void mouseEntered(final MouseEvent e) {
				button_1.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F3.png"));
			}
			public void mouseExited(final MouseEvent e) {
				button_1.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F4.png"));
			}
		});
		button_1.setToolTipText("停止服务");
		button_1.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F4.png"));
		toolBar_1.add(button_1);

		final JButton button_4 = new JButton();
		button_4.setToolTipText("查看服务器设置");
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				new Intercalate().showGUI();
			}
		});
		toolBar_1.add(button_4);
		button_4.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/S1.png"));

		toolBar_1.addSeparator();

		final JButton button_2 = new JButton();
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				new ShowAnent().showGUI();
			}
		});
		button_2.addMouseListener(new MouseAdapter() {
			public void mouseEntered(final MouseEvent e) {
				button_2.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/G1.png"));
			}
			public void mouseExited(final MouseEvent e) {
				button_2.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/G2.png"));
			}
		});
		button_2.setToolTipText("关于程序");
		button_2.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/G2.png"));
		toolBar_1.add(button_2);

		final JButton button_3 = new JButton();
		button_3.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/zhuxiao.png"));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				int i=JOptionPane.showConfirmDialog(frame,"确定要退出?","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
		 		if(i==0)
		 		{
		 			try {
		 				if(serverSocket!=null)serverSocket.close();
		 				t.interrupt();//中断服务线程
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						
					}
		 			System.exit(0);
		 		}
			}
		});
		button_3.setToolTipText("退出");
		toolBar_1.add(button_3);

		toolBar_1.addSeparator();

		label = new JLabel();
		toolBar_1.add(label);
		label.setText("处于停止服务中..");

		final JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBorder(BorderFactory.createTitledBorder("系统信息"));
		scrollPane.setBounds(0, 41, 451, 293);
		frame.getContentPane().add(scrollPane);

		textArea = new JTextArea();
		textArea.setEditable(false);
		textArea.setLineWrap(true);
		scrollPane.setViewportView(textArea);

		final JButton button_5 = new JButton();
		button_5.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String str=  sendtextArea.getText();
				Vector vc=new Vector();
				vc.add("系统信息");
				vc.add(str);
				Set keys =MainGUI.soceketMap.keySet();
	 			Iterator key_iter = keys.iterator();
	 			while(key_iter.hasNext()){//发给其他在线用户
	 				ObjectOutputStream tempoos = (ObjectOutputStream)MainGUI.soceketMap.get(key_iter.next());
	 				try {
	 					tempoos.writeObject(vc);
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
	 			}
				
				sendtextArea.setText("");
			}
		});
		button_5.setText("发送");
		button_5.setBounds(360, 374, 73, 25);
		frame.getContentPane().add(button_5);

		final JScrollPane scrollPane_2 = new JScrollPane();
		scrollPane_2.setBounds(0, 341, 354, 60);
		frame.getContentPane().add(scrollPane_2);
		scrollPane_2.setBorder(BorderFactory.createTitledBorder("发送系统消息"));

		sendtextArea = new JTextArea();
		sendtextArea.setLineWrap(true);
		scrollPane_2.setViewportView(sendtextArea);
		new Time().start();
	}
	public void showGUI()
	{
		frame.setResizable(false);
		frame.setSize(467,490);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
	class Time extends Thread
	{
		SimpleDateFormat sim=new SimpleDateFormat("hh:mm:ss");
		public void run()
		{
			while(true)
			{	int a=((int)(Math.random()*1000)+255)%255;
				int b=((int)(Math.random()*1000)+255)%255;
				int c=((int)(Math.random()*1000)+255)%255;
				time.setForeground(new Color(a,b,c));
				String str=sim.format(new Date(System.currentTimeMillis()));
				time.setText("当前时间为:"+str);
				try {
					sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		new MainGUI("20080001","001","5566").showGUI();
	}

}

⌨️ 快捷键说明

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