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

📄 bottompanel.java

📁 用java开发的QQ管理系统
💻 JAVA
字号:
package com.zlf.qqserver.usermngpanel;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.zlf.dao.DaoFactory;
import com.zlf.dao.UserDao;
import com.zlf.qq.pub.DataPacket;
import com.zlf.qqserver.Public;
import com.zlf.qqserver.ServerMain;

public class BottomPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JButton addBtn = new JButton("添加");

	private JButton deleteBtn = new JButton("删除");

	private JButton updateBtn = new JButton("修改");

	private JButton detailBtn = new JButton("详细");

	private JButton pwdBtn = new JButton("密码重置");
	
	private JDialog dialog;
	
	private UserDao userDao=DaoFactory.newInstance().createUserDao();
	private HashMap h=new HashMap();
	public BottomPanel(final ServerMain f) {
		// 增加
		addBtn.addActionListener(new AbstractAction() {

			/**
			 * 
			 */
			private static final long serialVersionUID = 5649572010609398449L;

			public void actionPerformed(ActionEvent e) {
				dialog = new JDialog(f, "添加新用户", true);
				dialog.setSize(450, 460);
				dialog.setResizable(false);
				dialog.setLocationRelativeTo(null);
				Container c = dialog.getContentPane();
				UserDialog addUserDialog = new UserDialog(0, dialog, f);
				c.add(addUserDialog);
				dialog.show();
			}
		});
		// 更新
		updateBtn.addActionListener(new AbstractAction() {

			/**
			 * 
			 */
			private static final long serialVersionUID = -1551897080686999442L;

			public void actionPerformed(ActionEvent e) {
				dialog = new JDialog(f, "修改用户信息", true);
				dialog.setSize(450, 460);
				dialog.setResizable(false);
				dialog.setLocationRelativeTo(null);
				Container c = dialog.getContentPane();
				UserDialog updateUserDialog = new UserDialog(1, dialog, f);
				c.add(updateUserDialog);
				dialog.show();

			}

		});
		// 删除
		deleteBtn.addActionListener(new AbstractAction() {

			/**
			 * 
			 */
			private static final long serialVersionUID = 7102367540272625807L;

			public void actionPerformed(ActionEvent e) {
				String id = (String) f.getUserMngPanel().getCenterPanel()
						.getDataModel().getValueAt(
								f.getUserMngPanel().getCenterPanel()
										.getUserTable().getSelectedRow(), 0);
				
				//友好提示
				
				if ((JOptionPane.showConfirmDialog(null, "确认删除该用户吗?", "友情提示", JOptionPane.YES_NO_OPTION)) != 0){
					return;
				}
				
				userDao.deleteUser(id);
				// 刷新表格
				h.put("1", "");
				Vector vector = userDao.selectUser(h);
				h.clear();
				f.getUserMngPanel().getCenterPanel().getDataModel().setData(
						vector);
				//改变按钮的状态
				f.getUserMngPanel().getBottomPanel().getDeleteBtn().setEnabled(false);
				f.getUserMngPanel().getBottomPanel().getUpdateBtn().setEnabled(false);
				f.getUserMngPanel().getBottomPanel().getDetailBtn().setEnabled(false);
				
				

				
				
				//
				// 选中某个用户,点击,强制其下线,发下线包
					//打包下线包
					HashMap tempdata=new HashMap();
					tempdata.put("data", "服务器将你删除了,程序将自动退出!");
					DataPacket downLinePacket=new DataPacket(DataPacket.server_close_type,DataPacket.Server_Id,"",tempdata);
					
					
					
					
					
					

					ArrayList a = (ArrayList) Public.mySocketInfo
								.get(id);

					if (a == null){
						com.zlf.qqserver.servermngpanel.toppanel.TopPanel.setTShow(id,7);
						
						return;
					}
					
					
					com.zlf.qqserver.servermngpanel.toppanel.TopPanel.setTShow(id,6);
					//取出用户编号对应的输出流,发给客户端下线包

					
					try {
						//给客户端发删除包
						ObjectOutputStream oos=(ObjectOutputStream) a.get(2);
						oos.writeObject(downLinePacket);
						oos.flush();
						//将用户删除
						//userDao.updateOnLine(0, id);
						userDao.deleteUser(id);
						Public.mySocketInfo.remove(id);
						
						
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				
				//更新显示在服务器端的上线用户信息
				h.put("9", "");
				Vector vector2 = userDao.selectUser(h);
				h.clear();
				f.getServerMngPanel().getTablePanel().getDataModel().setData(vector2);
				

				
			}




		});
		//详细按钮
		detailBtn.addActionListener(new AbstractAction() {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1807414618400089593L;

			public void actionPerformed(ActionEvent e) {
				dialog = new JDialog(f, "用户详细信息", true);
				dialog.setSize(450, 460);
				dialog.setResizable(false);
				dialog.setLocationRelativeTo(null);
				Container c = dialog.getContentPane();
				UserDialog updateUserDialog = new UserDialog(2, dialog, f);
				c.add(updateUserDialog);
				dialog.show();				
			}
			
		});

		pwdBtn.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				//密码重置
				userDao.updatePwd("", "123456");
			}
			
		});
		this.add(addBtn);
		this.add(deleteBtn);
		this.add(updateBtn);
		this.add(detailBtn);
		this.add(pwdBtn);
		
		deleteBtn.setEnabled(false);
		updateBtn.setEnabled(false);
		detailBtn.setEnabled(false);
	}

	public JButton getAddBtn() {
		return addBtn;
	}

	public void setAddBtn(JButton addBtn) {
		this.addBtn = addBtn;
	}

	public JButton getDeleteBtn() {
		return deleteBtn;
	}

	public void setDeleteBtn(JButton deleteBtn) {
		this.deleteBtn = deleteBtn;
	}

	public JButton getDetailBtn() {
		return detailBtn;
	}

	public void setDetailBtn(JButton detailBtn) {
		this.detailBtn = detailBtn;
	}

	public JButton getUpdateBtn() {
		return updateBtn;
	}

	public void setUpdateBtn(JButton updateBtn) {
		this.updateBtn = updateBtn;
	}

}

⌨️ 快捷键说明

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