您好,欢迎光临本网站![请登录][注册会员]  
文件名称: QQ聊天工具 基于java DB(数据库)
  所属分类: Java
  开发工具:
  文件大小: 10mb
  下载次数: 0
  上传时间: 2013-07-30
  提 供 者: u0112*****
 详细说明: package server.ui; import org.apache.log4j.Logger; import java.awt.Color; import java.awt.Font; import java.awt.event.*; import java.util.List; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.TitledBorder; import server.ServerDataBuffer; import server.model.service.UserService; import common.model.entity.*; /** 添加注册用户窗体 */ public class AddRegisterFrame extends JFrame { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(AddRegisterFrame.clas s); private static final long serialVersionUID = -768631070458723803L; private JPasswordField pwdFld; private JPasswordField pwd2Fld; private JTextField nickname; private JComboBox head; private JRadioButton sex0; private JRadioButton sex1; private JSpinner age; private JTextField cellphone; private JTextArea signature;// 个性签名 private JButton ok; private JButton reset; private JButton cancel; private JComboBox department;// 处于哪个部门 private Long id; public AddRegisterFrame(Long id) { this.id = id; this.init(); // 关闭窗口 // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setResizable(false); } public void init() { if (logger.isDebugEnabled()) { logger.debug("init() - start"); //$NON-NLS-1$ } this.setTitle("用户添加"); this.setSize(400, 500); // 设置默认窗体在屏幕中央 this.setBounds((ServerDataBuffer.screenSize.width - 400) / 2, (ServerDataBuffer.screenSize.height - 500) / 2, 400, 500); getContentPane().setLayout(null); // 昵称 Font font = new Font("client", Font.PLAIN, 15); JLabel label = new JLabel("昵称:*"); label.setFont(font); label.setBounds(45, 40, 59, 17); getContentPane().add(label); nickname = new JTextField(); nickname.setBounds(100, 35, 120, 23); getContentPane().add(nickname); // 密码 JLabel label2 = new JLabel("密码:*"); label2.setFont(font); label2.setBounds(45, 80, 59, 17); getContentPane().add(label2); pwdFld = new JPasswordField(); pwdFld.setBounds(100, 75, 120, 23); getContentPane().add(pwdFld); // 确认密码 JLabel label3 = new JLabel("确认密码:*"); label3.setFont(font); label3.setBounds(15, 121, 79, 17); getContentPane().add(label3); pwd2Fld = new JPasswordField(); pwd2Fld.setBounds(100, 115, 120, 23); getContentPane().add(pwd2Fld); // 性别 JLabel label5 = new JLabel("性别:*"); label5.setFont(font); label5.setBounds(45, 155, 40, 23); getContentPane().add(label5); sex1 = new JRadioButton("男", true); sex1.setFont(font); sex1.setBounds(100, 155, 50, 23); getContentPane().add(sex1); sex0 = new JRadioButton("女"); sex0.setFont(font); sex0.setBounds(160, 155, 50, 23); getContentPane().add(sex0); ButtonGroup buttonGroup = new ButtonGroup();// 单选按钮组 buttonGroup.add(sex0); buttonGroup.add(sex1); // 年龄 JLabel label7 = new JLabel("年龄"); label7.setFont(font); label7.setBounds(250, 155, 44, 24); getContentPane().add(label7); // age = new JComboBox(); // age.setBounds(285, 155, 50, 24); // age.setFont(font); // age.setMaximumRowCount(10); // for (int i = 0; i < 120; i++) // { // age.addItem(i); // } // age.setSelectedIndex(-1); // getContentPane().add(age); SpinnerNumberModel model = new SpinnerNumberModel(20, 0, 120, 1); age = new JSpinner(model); age.setBounds(285, 155, 60, 24); getContentPane().add(age); // 手机号码 JLabel label6 = new JLabel("手机号码:"); label6.setFont(font); label6.setBounds(15, 195, 80, 23); getContentPane().add(label6); cellphone = new JTextField(); cellphone.setBounds(100, 195, 150, 23); getContentPane().add(cellphone); // 所属部门 JLabel label4 = new JLabel("所属部门:*"); label4.setFont(font); label4.setBounds(15, 235, 79, 17); getContentPane().add(label4); department = new JComboBox();// 下拉列表图标 department.setBounds(100, 230, 150, 23); department.setMaximumRowCount(4); department.setFont(font); department.addItem("人事部门"); department.addItem("市场部门"); department.addItem("计划部门"); department.addItem("财务部门"); department.addItem("行政部门"); department.addItem("销售部门"); department.addItem("客服部门"); department.addItem("采购部门"); department.setSelectedIndex(-1); getContentPane().add(department); // 个性签名 signature = new JTextArea(); signature.setBounds(25, 280, 350, 120); signature.setBorder(BorderFactory.createEtchedBorder()); Border border = signature.getBorder(); signature.setBorder(BorderFactory.createTitledBorder(border, "个性签名", TitledBorder.LEFT, TitledBorder.TOP, font)); // 换行 signature.setLineWrap(true); getContentPane().add(signature); // 头像 head = new JComboBox(); head.setBorder(BorderFactory.createLineBorder(Color.GRAY)); Border border1 = head.getBorder(); head.setBorder(BorderFactory.createTitledBorder(border1, "头像", TitledBorder.LEFT, TitledBorder.TOP)); head.setBounds(250, 36, 90, 75); head.setMaximumRowCount(4); for (int i = 0; i < 11; i++) { head.addItem(new ImageIcon(AddRegisterFrame.class.getResource("/images/" + i + ".jpg"))); } head.setSelectedIndex(0); getContentPane().add(head); // 取消 cancel = new JButton("退出"); cancel.setBounds(30, 420, 70, 20); getContentPane().add(cancel); // 重置 reset = new JButton("重置"); reset.setBounds(120, 420, 70, 20); getContentPane().add(reset); // 确认 ok = new JButton("确认"); ok.setBounds(300, 420, 70, 20); getRootPane().setDefaultButton(ok); getContentPane().add(ok); // 取消按钮监听事件处理 cancel.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { if (logger.isDebugEnabled()) { logger.debug("$ActionListener.actionPerformed(ActionEvent) - start"); //$NON-NLS-1$ } AddRegisterFrame.this.dispose(); if (logger.isDebugEnabled()) { logger.debug("$ActionListener.actionPerformed(ActionEvent) - end"); //$NON-NLS-1$ } } }); // 关闭窗口 this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (logger.isDebugEnabled()) { logger.debug("$WindowAdapter.windowClosing(WindowEvent) - start"); //$NON-NLS-1$ } AddRegisterFrame.this.dispose(); if (logger.isDebugEnabled()) { logger.debug("$WindowAdapter.windowClosing(WindowEvent) - end"); //$NON-NLS-1$ } } }); // 重置按钮监听事件处理 reset.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { if (logger.isDebugEnabled()) { logger.debug("$ActionListener.actionPerformed(ActionEvent) - start"); //$NON-NLS-1$ } nickname.setText(""); pwdFld.setText(""); pwd2Fld.setText(""); cellphone.setText(""); nickname.requestFocusInWindow();// 用户名获得焦点 if (logger.isDebugEnabled()) { logger.debug("$ActionListener.actionPerformed(ActionEvent) - end"); //$NON-NLS-1$ } } }); // 确认按钮监听事件处理 ok.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { if (logger.isDebugEnabled()) { logger.debug("$ActionListener.actionPerformed(ActionEvent) - start"); //$NON-NLS-1$ } if (pwdFld.getPassword().length == 0 || pwd2Fld.getPassword().length == 0) { JOptionPane.showMessageDialog(AddRegisterFrame.this, "带 “ * ” 为必填内容!"); // 判断用户名和密码是否为空 } else if (!new String(pwdFld.getPassword()).equals(new String( pwd2Fld.getPassword()))) { JOptionPane.showMessageDialog(AddRegisterFrame.this, "两次输入密码不一致!"); pwdFld.setText(""); pwd2Fld.setText(""); pwdFld.requestFocusInWindow(); // 判断两次密码是否一致 } else { User user = new User(new String(pwdFld.getPassword()), nickname.getText(), sex0.isSelected() ? '女' : '男', head.getSelectedIndex(), ((Integer) age.getValue()) .intValue(), Long.valueOf(cellphone .getText()), String.valueOf(department .getSelectedItem()), signature.getText()); user.setId(getId()); UserService userService = new UserService(); List users =userService.loadAllUser(); // 添加用户 users.add(user); userService.saveAllUser(users); ServerDataBuffer.registedUserTableModel.add(new String[] { String.valueOf(user.getId()), user.getPassword(), user.getNickname(), String.valueOf(user.getSex()), String.valueOf(user.getAge()), String.valueOf(user.getCellphone()), user.getDepartment() }); ServerDataBuffer.registedUserMap.put(user.getId(), user); JOptionPane.showMessageDialog(AddRegisterFrame.this, "用户添加成功," + "\n\n" + "你添加的用户帐号是" + user.getId(), "添加成功", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(AddRegisterFrame.class.getResource("/images/duihao.png"))); AddRegisterFrame.this.dispose(); } if (logger.isDebugEnabled()) { logger.debug("$ActionListener.actionPerformed(ActionEvent) - end"); //$NON-NLS-1$ } } }); if (logger.isDebugEnabled()) { logger.debug("init() - end"); //$NON-NLS-1$ } } public Long getId() { return id; } public void setId(Long id) { this.id = id; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 输入关键字,在本站1000多万海量源码库中尽情搜索: